Closed caleb-at-pieces closed 9 months ago
Try toggling off the plugin in the Community Plugins listing: if "stale" code or dom elements persist, the problem isn't in Hot Reload, but in the plugin.
Reloading Obsidian to work around unloading bugs in a plugin is not a good idea, but if you must do it, you can simply hit Ctrl-R in the dev console, or use the builtin Obsidian command, "Reload app without saving". These operations are not part of hot reload for a good reason: they can easily cause data loss if done automatically rather than manually.
You should also check your plugin to make sure that you haven't written an unload()
method - the correct method name is onunload()
and if you wrote unload()
instead you will end up with stale forms of everything that was done/registered with plugin methods (like adding commands, status bar item, views, event handlers, markdown processors, etc).
I have been using the hot reload plugin for some time now during development for my team's Obsidian plugin.
I have started to notice some issues, especially as the project grows primarily due to stale JS code that continues to run after the plugin gets reloaded. This seems to be worsened as it seems that the unload function within the plugin is not ran during the hot reloading process, meaning my websocket connections will grow n times with the number of reloads, and so will my dom elements that aren't cleared as a part of the loading process.
There may be something I could do better on my side, but a really simple fix for me is running window.location.reload(), performing a full reload of obsidian instead of reloading the singular plugin.
It may be worthwhile to add a setting to do this for the larger plugins in the space that may be able to benefit from this, I'll even do it myself depending on what the maintainers of this repo think!