-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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: Styles lost during HMR mode when using Client Data/SPA Mode #8466
Comments
With the information you provided here, I am not 100% sure if this is the same root issue but please have a look at the following issues: It seems like this is related to the DOM being manipulated after rendering the content in the page. (oversimplified explanation) |
There are no hydration issues involved with this issue so I don't think those are quite the same cause |
Ok it was worth a try :) |
Welp, it turns out you were (at least partially) right! Even though this issue doesn't have hydration errors - it seems the root cause is something to do with how React handles updates to the The issue was tracked down to the following scenario (happens in both Remix + Client Data and Remix SPA mode):
For now, the workaround would be:
Also note that this is only a dev-time HMR problem in vite and side-effect imports in |
Glad I was helpful or at least pointed you to the right place. 👍🏽 |
Trying out SPA mode and running into this issue. Wanted to mention that this even happens when there are side-effect CSS imports outside of |
I'm debugging this issue too; anyone can point me to the files that implements the spa pipeline ? thanks |
I've added some docs to the Remix + Vite troubleshooting guide covering this issue, along with a couple of ways to fix it: https://remix.run/docs/en/main/future/vite#styles-disappearing-in-development-when-document-remounts |
@markdalgleish If I understand the guide correctly, is removing the HydrateFallback/ErrorBoundary on root all it takes to make HMR work nicely again? I just tried it and it doesn't seem to be working (a fork without a HydrateFallback in case I'm doing something wrong). But I can confirm that it's fixed on canary releases of React. And regarding package.json overrides, I don't think npm allows you to override packages that you directly depend on. It certainly didn't work for me, and the docs seem to confirm that:
|
@avinashbot Nice catch with the overrides, I've fixed the example on the site. I'll double check the other point you raised tomorrow. |
@avinashbot Removing the |
I've updated the docs to focus on canaries as the solution to this problem since I missed some nuances around |
@markdalgleish @brophdawg11 are you guys planning to ship Remix with 18.3 canary by default in next releases? |
No - you are in charge of the react version for your app, not us |
Closing this as there's nothing further that Remix can do about it. As shared by Mark, we've documented that the fix is included as part of React canary. |
Just wanted to add: I noticed hydration issues relating to browser plugins (as determined by lack of console warning in an Incognito browser with most plugins disabled - only Adblock and my pass manager are enabled in incognito so clearly none of them are the cause) Based on some of the above chatter, i thought this might be causing the styling reload issues... lo and behold, hot reload works perfectly in incognito. Hope this is helpful for someone else... Update: disabling Urban VPN extension fixes the issue for me (side note: what in the heck is that doing injecting code onto my page???) style.reload.issue.mp4 |
I wonder why this issue was closed while the issue facebook/react#24430 is not? And is the doc outdated here as the canary version is now react 19 instead? Should it be updated to |
Whoa. That solved it for me. In case it's helpful for somebody else for me it's the Bitwarden Password Manager extension (on Firefox), which is strange because I see it in shmuli9's video in both cases. I'm running uBlock Origin and Ghostery as well, neither of which break the HMR, only Bitwarden does. Edit: It starts working when I disable the "Ask to save and use passkeys" option in Notifications settings in Bitwarden Password Manager extension. Weirdly, adding |
Reproduction
Use a side effect import in root to load styles
Add a clientLoader and HydrateFallback to root so it SSR's a fallback
Load / and see styles only exist on
HydrateFallback
's render but are lost when we flip over to rootSystem Info
Used Package Manager
npm
Expected Behavior
Styles persist on load and on subsequent HMR
Actual Behavior
Styles lost on load (and during any subsequent HMR)
The text was updated successfully, but these errors were encountered: