Repository navigation
Conversation
In development, use stable hrefs (componentId only) on RSC style tags so React 19 replaces them on hot reload instead of treating each CSS content change as a new permanent resource. In production, content-aware hrefs are preserved for correct dynamic variant deduplication. The tradeoff: dynamic prop variants may incorrectly dedup in dev mode (e.g., two instances with different $bg props share one style tag). This is acceptable since dev mode prioritizes HMR correctness and the styles still render — just with one variant potentially overriding the other until a full page refresh. Closes #5670
🦋 Changeset detectedLatest commit: 67016f7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Instead of using stable hrefs (which causes React 19 to deduplicate dynamic variant style tags), omit precedence and href entirely in development. React then treats <style> as a regular element that unmounts on re-render, preventing stale tag accumulation during HMR. Production behavior is unchanged — content-aware hrefs are preserved for correct deduplication of shared base styles.
Contributor
Author
|
Available to test via |
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.
Summary
sc-{componentId}only) on RSC<style>tags so React 19 replaces them on hot reload instead of treating each CSS content change as a new permanent resourceBackground
When styles change during HMR, the CSS content hash changes, producing a new
href. React 19 treats<style precedence="...">tags as permanent resources keyed byhref— two different hrefs = two separate tags, neither removed. This causes stale style tags to accumulate, and stale&-based selectors keep matching because they use the stable component ID class.Tradeoff
Dynamic prop variants (e.g.,
$bg="red"vs$bg="blue") may incorrectly dedup in dev mode since they share the same stable href. This is acceptable because:History check
hrefprop for a <style> tag opting into hoisting semantics using theprecedenceprop to not have any spaces but ecountered spaces instead. #5663 (Feb 17) for dedup correctness — HMR was not consideredcreateGlobalStylealready avoidsprecedenceentirely (different mechanism)Test plan
Closes #5670