Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast Refresh infinite loop #51

Open
alebanzas opened this issue Nov 29, 2022 · 14 comments
Open

Fast Refresh infinite loop #51

alebanzas opened this issue Nov 29, 2022 · 14 comments
Labels
bug Something isn't working

Comments

@alebanzas
Copy link

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
      },
    },
 ],
@RDIL
Copy link
Member

RDIL commented Nov 29, 2022

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

@RDIL RDIL closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2022
@alebanzas
Copy link
Author

Updated it to 2.2.0 and still looping

@RDIL RDIL reopened this Nov 30, 2022
@RDIL
Copy link
Member

RDIL commented Nov 30, 2022

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

@doroncy
Copy link

doroncy commented Dec 1, 2022

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

@RDIL
Copy link
Member

RDIL commented Dec 1, 2022

@doroncy same project?

@RDIL RDIL added the bug Something isn't working label Dec 6, 2022
@thomasheartman
Copy link

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.

@RDIL
Copy link
Member

RDIL commented Jan 4, 2023

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!

@thomasheartman
Copy link

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

@FilipPyrek
Copy link

Same issue here 🤚 Looking forward to the resolution. Thanks for the plugin btw. 🙏

@RDIL
Copy link
Member

RDIL commented Jan 27, 2023

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.

@dtbuchholz
Copy link

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

thomasheartman added a commit to Unleash/unleash that referenced this issue Sep 1, 2023
This change sets `noRuntimeDownloads` to `true` for
`plugin-remote-content'` to avoid the infinite loop issue mentioned in
rdilweb/docusaurus-plugin-remote-content#51,
as described in
https://github.com/rdilweb/docusaurus-plugin-remote-content#noruntimedownloads.

I suspect that this will require you to generate the files before
running the doc build, which may be an issue. However, this does stop
the doc from building over and over.
thomasheartman added a commit to Unleash/unleash that referenced this issue Nov 6, 2023
…4596)

This change sets `noRuntimeDownloads` to `true` for
`plugin-remote-content'` to avoid the infinite loop issue mentioned in
rdilweb/docusaurus-plugin-remote-content#51,
as described in

https://github.com/rdilweb/docusaurus-plugin-remote-content#noruntimedownloads.

It also updates some of the yarn scripts to generate the required files before `yarn start`, `yarn build`, and `yarn deploy`.

To manually generate the files, run:

```bash
yarn docusaurus download-remote-content-external
yarn docusaurus download-remote-content-sdks
```
@colececil
Copy link

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
Copy link

Also, see facebook/docusaurus#4138 for a proposed "middleware" feature to official Docusaurus plugins that I think would solve this problem.

@RDIL
Copy link
Member

RDIL commented Jan 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

7 participants