Open alebanzas opened 2 years ago
You need to update your @docusaurus/core
version, you're on an out-of-date version which isn't supported by the plugin.
Updated it to 2.2.0 and still looping
@alebanzas did you update all your @docusaurus
packages to the same version? If not, you may have old versions lingering.
I also have the same behavior of looping while on docusaurus 2.2.0
@doroncy same project?
Hey ππΌ I think I'm seeing the same issue. All docusaurus packages are version 2.2.0. It runs once on startup, but then it seems to create an infinite loop whenever I modify or remove a file. I've primarily been working with the sidebar and docusaurus.config files, but saw the same when deleting other files picked up by docusaurus.
I'd be happy to provide any more details if you need them. And for the record: I have no affiliation with the other reporters in this thread, so it's a different project.
Hey all, so to be honest, I have no idea what's causing this. I've asked the maintainers of Docusaurus to take a look, as they probably will know. I'm sorry this is still happening and causing frustration!
Thanks for the update! And that's perfectly fine π It's pretty benign, just a little annoying ππΌ
I worked with it a bit today and found that some things seem to trigger it, while others don't:
Changing docusaurus.config (as you might do when you're first setting up the plug-in) definitely does. Deleting a file created by the plugin also seems to cause it.
On the other hand, changing other, unrelated files did not trigger it for me, I think. I also think that changing a file that was require'd by the Docusaurus config was okay (but I would need to double check that to be 100%).
So once it's set up, I think it should be mostly fine from there. Still, it'd be nice to get to the bottom of it, but I don't think anyone should be losing sleep over it βΊοΈ
Same issue here π€ Looking forward to the resolution. Thanks for the plugin btw. π
I haven't forgotten about this issue, this is what the maintainers of Docusaurus had to say. I'm going to look for a workaround.
note: if you set noRuntimeDownloads: true
in your docusaurus config, this should resolve the issue
Hey, I happened to run into this same issue yesterday trying to write a Docusaurus plugin with similar functionality. (I was looking at this plugin's code as a reference, which is how I ended up here.)
I figured out a way to work around the issue, so I thought I'd share the solution here. The problem is that anytime a file is updated in a directory that's watched by any plugin, a reload is triggered and the loadContent
function is called on all plugins. So if this plugin is configured to write to /docs
and a reload gets triggered, this plugin rewrites the files to /docs
. But since /docs
is watched by @docusaurus/plugin-content-docs
, each of the files this plugin updates in /docs
triggers another reload, which causes this plugin's loadContent
function to get called again... which results in an infinite loop.
The solution I came up with is to only write to /docs
when at least one of the following conditions are met. (This way, if no changes to /docs
are necessary, I avoid writing to it, which prevents a reload from getting triggered.)
/docs
needs to change./docs
./docs
.For scenario 1 above, I had to write some code to check if the file I'm about to write to /docs
already exists there, and to check if it already contains the same content I'm about to write. If those conditions are both true, then I skip writing the file, since there's nothing to change.
For scenario 3 above, I had to move my "cleanup" code to the end of my loadContent
function. Because of the sequence change, I also had to modify that code so instead of deleting all files from the destination directory, it only deletes any "extra" ones that aren't expected to be there.
Even with these changes, there will still be at least one unnecessary reload because of the write to /docs
. But it's much better than an infinite loop! π
I hope this helps!
Also, see https://github.com/facebook/docusaurus/issues/4138 for a proposed "middleware" feature to official Docusaurus plugins that I think would solve this problem.
Interesting discovery, thanks for letting me know. I'll keep a watch on the middleware proposal, and in the meantime, I'm happy to review any PRs that anyone sends to fix the bug - I don't currently have time to fix it myself sadly.
localhost keeps hot reloading even though no changes are made
docusaurus.config.js