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

[Bug] Weird behavior of Remix in dev mode #1884

Closed
lagz0ne opened this issue Feb 11, 2022 · 5 comments
Closed

[Bug] Weird behavior of Remix in dev mode #1884

lagz0ne opened this issue Feb 11, 2022 · 5 comments
Labels
docs PR Welcome We would love a PR addressing this issue

Comments

@lagz0ne
Copy link

lagz0ne commented Feb 11, 2022

What version of Remix are you using?

1.1.3

Steps to Reproduce

Environment
Windows 11
WSL2

Reproducible code https://github.com/lagz0ne/remix-bug

The code doesn't really work in Dev mode but works well in Production mode
The action part seems to be called but didn't persist the change to the content. As such, the loader takes the content from the original stage, not sure this has anything to do with the model of rebuilding (please have a look at the index route in the repository).

Expected Behavior

Works in Dev mode

Actual Behavior

Doesn't function in dev mode

@lagz0ne lagz0ne added the bug Something isn't working label Feb 11, 2022
@lagz0ne lagz0ne changed the title Weird behavior of Remix in dev mode [Bug] Weird behavior of Remix in dev mode Feb 11, 2022
@cmd-johnson
Copy link
Contributor

cmd-johnson commented Feb 11, 2022

See #1818 and #1832.
In dev mode, Remix currently purges the require cache on every single request, meaning your cache object will be initialized to ["1"] every time you navigate to your Index route.

You can work around this by attaching your cache to the global object. This is how I did it:

const cache = (() => {
  const globalCache = global as { cache?: string[] };
  if (!globalCache.cache) {
    globalCache.cache = ["1"];
  }
  return globalCache.cache;
})();

(If you do this in different parts of the app, you might want to use a more specific name than just cache to add to the global object to prevent name clashes)

This might be a bit verbose, but it's probably the best you can do for now. Just remember that when using the global object, the cache will only be re-created when you restart your dev server. So every time you change your cache initialization code, you'll have to manually restart your app.

@lagz0ne
Copy link
Author

lagz0ne commented Feb 11, 2022

Thank @cmd-johnson, that's an awesome explanation and work around

@machour machour added docs and removed bug Something isn't working labels Apr 12, 2022
@machour
Copy link
Collaborator

machour commented Aug 2, 2022

This is already described in https://remix.run/docs/en/v1/other-api/serve, but could benefit from an additional example and workaround as provided by @cmd-johnson

@machour machour added the PR Welcome We would love a PR addressing this issue label Aug 2, 2022
@balzdur
Copy link

balzdur commented Jan 9, 2023

It may be similar to this issue.

A promising solution is proposed here.

In the meantime, you can use patch-package as proposed here.

UPDATE: for v1.10.1 you can use the new patch provided here

@pcattori
Copy link
Contributor

Fixed by #5133 which will make the new dev server available in the next minor release under the unstable_dev future flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PR Welcome We would love a PR addressing this issue
Projects
None yet
Development

No branches or pull requests

5 participants