fix(rsc): hot module replacement of CSS for nested RSC with cssLinkPrecedence: false #1188
Open
jantimon wants to merge 6 commits intovitejs:mainfrom
Open
fix(rsc): hot module replacement of CSS for nested RSC with cssLinkPrecedence: false #1188jantimon wants to merge 6 commits intovitejs:mainfrom
jantimon wants to merge 6 commits intovitejs:mainfrom
Conversation
Contributor
|
Hey thanks for digging. Also, if you have a fix, please feel free to push here to verify the fix. |
Author
|
This pr fixes the bug in vite-plugin-react rsc for vite-hmr.mp4However it introduces a new issue for the tanstack integration where we will need the help of @schiller-manuel to find the best approach. The problem is that it does not fix the removal of css props as old css styles now stay in DOM because of the cache busting
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

I saw a bug in CSS HMR when trying out RSC in Tan Stack start https://tanstack.com/blog/react-server-components
Actually I wanted to see if RSC works well in TanStack and allows the css of next-yak static css-in-js plugin to be hot reloaded: DigitecGalaxus/next-yak#529
It seems that a server component whose module lives only in the
rscVite environment (not in the client bundle) is rendered through a nested RSC Flight stream.What the bug does
Editing a CSS file that is only imported from a Server Component rendered through a nested RSC Flight stream does not reliably update the page. The first edit in a dev session often appears to work (via a Vite side-effect), but any subsequent edit in the same session is silently ignored. So every HMR message after that sits behind a hung promise on the client. Users see the page stuck on edit‑1 CSS until a full page reload or dev-server restart.
Scope / who is affected
cssLinkPrecedence: falsee.g TanStack Start.createServerFn+renderServerComponent, etc.).cssLinkPrecedence: true, React 19 Float-managed) is unaffected — the fix is narrowly gated so it does not change that path.The three-part fix (in
plugin-rsc/src/plugin.ts)hotUpdate(rsc env). Walk the importer chain from the changed CSS and invalidate only the\0virtual:vite-rsc/css?type=rsc&…modules. JS importers (inner.tsx, server.tsx, root.tsx) are intentionally left untouched to avoid regressing the Float-managed default path<link href>incollectCss. Only whencssLinkPrecedence: falseand the consumer isn't alreadyclient, append?t=<lastHMRTimestamp>. The default Float path stays bare-href so Vite's in-place<link>swap keeps workinghotUpdate. WhencssLinkPrecedence: falseand the changed CSS has no client-side JS importer, return[]. This is what prevents Vite'sPromise.allfrom hanging on a React-owned<link>that gets unmounted mid-swap.. and that hang was the reason only the first edit ever appeared to work