docusaurus-plugin-remote-content icon indicating copy to clipboard operation
docusaurus-plugin-remote-content copied to clipboard

Fast Refresh infinite loop

Open alebanzas opened this issue 2 years ago β€’ 14 comments

localhost keeps hot reloading even though no changes are made

image

docusaurus.config.js

[
    "docusaurus-plugin-remote-content",
    {
        name: "some-name-readme",
        sourceBaseUrl: "https://someurl.com/file.md",
        outDir: "docs/xyz/",
        documents: ["README.md"],
        modifyContent(filename, content) {
          if (filename.includes("README")) {
              return { content: "# some title \n\n #" + content }
          }
          return undefined
      },
    },
 ],

alebanzas avatar Nov 29 '22 12:11 alebanzas

You need to update your @docusaurus/core version, you're on an out-of-date version which isn't supported by the plugin.

RDIL avatar Nov 29 '22 17:11 RDIL

Updated it to 2.2.0 and still looping

alebanzas avatar Nov 30 '22 12:11 alebanzas

@alebanzas did you update all your @docusaurus packages to the same version? If not, you may have old versions lingering.

RDIL avatar Nov 30 '22 18:11 RDIL

I also have the same behavior of looping while on docusaurus 2.2.0

doroncy avatar Dec 01 '22 11:12 doroncy

@doroncy same project?

RDIL avatar Dec 01 '22 17:12 RDIL

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.

thomasheartman avatar Jan 03 '23 13:01 thomasheartman

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!

RDIL avatar Jan 04 '23 16:01 RDIL

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 ☺️

thomasheartman avatar Jan 04 '23 16:01 thomasheartman

Same issue here 🀚 Looking forward to the resolution. Thanks for the plugin btw. πŸ™

FilipPyrek avatar Jan 16 '23 19:01 FilipPyrek

Screenshot 2023-01-27 at 17 02 59 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.

RDIL avatar Jan 27 '23 22:01 RDIL

note: if you set noRuntimeDownloads: true in your docusaurus config, this should resolve the issue

dtbuchholz avatar Aug 21 '23 20:08 dtbuchholz

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.)

  1. The content of an existing file in /docs needs to change.
  2. A new file needs to be added to /docs.
  3. An old file needs to be deleted from /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!

colececil avatar Jan 19 '24 00:01 colececil

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.

colececil avatar Jan 19 '24 19:01 colececil

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.

RDIL avatar Jan 20 '24 01:01 RDIL