-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Vite dev server crashes Remix / React when reloading after finding new dependencies to optimize #10156
Comments
I have seen a similar thing before, but it was hard to reproduce. |
A fix for this would be great please, thank you |
I'm also experiencing this issue! Would love to see a fix 🙏 |
From what I understand, its causing a hook error due to two versions of React. But this is sort of beyond my React paygrade to solve. |
@joshbuddy, I found a similar issue on Github that suggested the same thing about different react versions. I'll keep poking around to see what can I do to find where this other version of React is coming from 👀 |
My guess at what is happening under the hood is that the two versions of react are coming from two different builds, and both builds are being loaded simultaneously. Conspicuously, if I do a hard refresh, Safari behaves normally again. |
I think the hard refresh fix is due to the fact that the new optimized dependency is already loaded in |
Adding the server: {
warmup: {
clientFiles: ['app/**/*.tsx'],
},
}, |
I'm running into this issue. Seems to be specific to safari in my case, on iOS and mac. @joshbode your config has somewhat helped but it still seemed to happen on occasion. Very strange - and annoying! |
i'm also running into this issue, thought i was going mad, unfortunately @joshbode's config didnt seem to help. i'm migrating an older remix app to the new vite approach and attempting to get it running on cloudflare workers. a simple page refresh after the error is hit and everything is hunky-dory, but its not a great dev-experience. |
This is exactly the behaviour we're seeing and it's also a migration from an older remix on CF workers to vite. |
I was hoping the combination of #9921 and enabling |
Check if this PR #10258 fixes your issue. I have similar issue on Windows for a while and and I decided to debug it. Seems to be related on how Remix build the route's file path into the |
I've only had the chance to test this in one app so far, but it's looking good! I haven't seen the annoying behavior since applying this patch. 🎉 🤞 |
Nice! The problem is both how Remix generate the |
@halljus I've configure the entries path manually using @brophdawg11 Is your team can look at this issue? I suggest to check with Vite and tinyglobby devs to fix this issue all together. Thanks optimizeDeps: {
// Configure Remix plugin optimizeDeps entries since is has a bug on Windows
// TODO: Check if the issue has been fixed
// @see https://github.com/remix-run/remix/pull/10258
entries: ['./app/entry.client.tsx', './app/root.tsx', './app/routes/**/*.tsx'],
}, |
@sebastien-comeau FWIW, I only patched |
@halljus Correct, I wish Remix or Vite wouldn't cause that issue but for now I prefer specify it and remove it when it's fixed. I've used |
Interesting insights @sebastien-comeau, given that OP is running |
I don't know @clgeoio. @astonfuture would have to test on his side to see if it's related. |
Reproduction
https://github.com/astonfuture/remix-vite-optimize-dependency-crash
Run the dev server and force clear vite's cache:
npm run dev -- --force
or deletenode_module/.vite
thennpm run dev
Navigate to the index
http://localhost:5173
Directly navigate to
page-two
by typinghttp://localhost:5173/page-two
in the address bar and hitting enterVite detects the new dependency (
lodash-es
), runs the optimization and reloads the page which causes it to crash with hydration errors.System Info
Used Package Manager
npm
Expected Behavior
There should not be hydration errors which crash the page as you navigate
Actual Behavior
The reproduction repo above is the official Remix Cloudflare workers template with one extra route added. The new route imports a package (lodash-es) and uses it in the component. When you navigate to that page, vite detects the new package and runs its optimizer which causes a page reload. This causes all manner of errors and the page crashes.
Starting the dev server
When navigating to a page with new dependencies:
Page crashes with a white screen with console errors in the browser such as:
Reloading the page after it crashes works fine, leading me to believe this has something to do with the HMR that happens when vite reloads.
The text was updated successfully, but these errors were encountered: