remix-run / remix

Build Better Websites. Create modern, resilient user experiences with web fundamentals.
https://remix.run
MIT License
29.93k stars 2.52k forks source link

v2 - HMR does not work, probably race condition (error loading dynamically imported module) #7466

Closed akomm closed 2 months ago

akomm commented 1 year ago

What version of Remix are you using?

2.0.0 update: 2.0.1 tested, still present

Are all your remix dependencies & dev-dependencies using the same version?

Steps to Reproduce

Just install this template as in README.md:

https://github.com/remix-run/remix/tree/main/templates/remix

Try change root.tsx in dev mode

Expected Behavior

content is reloaded

Actual Behavior

Uncaught (in promise) TypeError: error loading dynamically imported module: http://localhost:3000/build/root-JFW4ZMF3.js?t=1695047812275

The file hash and timestamp obviously vary.

Tested with: Firefox 106 Chromium 116

pcattori commented 11 months ago

There's a couple different issues being conflated in this thread. Here are my current thoughts for disentangling them:

Issue 1: remix dev without --manual

If you are not using the -c flag for a custom server, there should be no reason not to use the --manual flag as it provides better DX anyway. remix dev without --manual should work too; if it doesn't currently, that's a bug. But in any case, I'd recommend just using remix dev --manual:

- remix dev
+ remix dev --manual

If you are using the -c flag for a custom server, check out our docs for manual mode.

Issue 2: wrangler + HMR

HMR seems to only work with wrangler <= 3.8.0 . Unsure if this is a bug in newer wrangler versions or (more likely) a race condition that is only prevalent for wrangler 3.9+. These sort of "file access" race conditions are only possible because we are coordinating the app server and the dev server via file writes (i.e. writing the server build to disk).

The principled solution is to not rely on files at all for coordination, which is exactly what Vite does. In fact, solving this type of race condition is exactly what first motivated me to look into Vite.

So in all likelihood, the workaround will be to stay on wrangler <= 3.8 until Vite (w/ CloudFlare support) is stabilized. Which is literally the thing I'm working on now. No promises on exact date, but rest assured its actively being worked on.

Other issues

If you have issues other than the two I mentioned here, it'd be great to track those in separate GitHub issues with specifics for your particular issue so we can make sure to prioritize those fixes accordingly.

msakrejda commented 10 months ago

I'm seeing the same behavior as described in this comment in a fresh Remix 2.4.1 project. The only difference is that switching to express did not fix the issue for me. Editing out the line in remix-serve.js did fix it.

akomm commented 10 months ago

I'm seeing the same behavior as described in this comment in a fresh Remix 2.4.1 project. The only difference is that switching to express did not fix the issue for me. Editing out the line in remix-serve.js did fix it.

custom server only fixed it because it was used in combination with the --manual flag. I did not mentioned it in the comment, because I did it before. Just wanted to clarify. Maybe you do not need to edit the line if you add --manual flag.

pcattori commented 2 months ago

Closing this since Remix Vite has obsoleted the old esbuild-based dev server that used the --manual flag.