fix: shared-group global styles and eager keyframes registration#5696
Merged
Conversation
🦋 Changeset detectedLatest commit: b621feb 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 |
7bba068 to
3efd62c
Compare
Contributor
Author
|
This PR is testable via |
This was referenced Mar 20, 2026
All instances of a createGlobalStyle component now share a single stylesheet group, registered once at definition time. This fixes unmounting one instance removing styles for other still-mounted instances — a recurring bug family spanning #5695, #3146, #3008, #3022. Keyframes now eagerly register their group ID at construction time, so keyframes defined before a component appear before it in CSS output. The ordering algorithm is fully deterministic: CSS injection order is determined at definition time (when styled(), createGlobalStyle(), or keyframes() is called), not at render time.
- Reorder sections: critical constraints first, reference material last - Remove file listings (discoverable via filesystem, zero protective value) - Condense performance patterns into table, remove negative results - Extract mermaid rendering flow diagram to docs/rendering-flow.md - Fix IS_RSC description: clarify build-time vs runtime behavior - Consolidate duplicate server-detection and clearTag guidance - Move misplaced server-detection bullet from attrs to build architecture - 262 lines → 107 lines (59% reduction)
5535d54 to
b621feb
Compare
quantizor
added a commit
that referenced
this pull request
Mar 21, 2026
The keyframeIds Set, KEYFRAMES_ID_PREFIX constant, and reconstructWithOptions copy were dropped when rebasing against main (which merged #5696 with a different Sheet.ts).
quantizor
added a commit
that referenced
this pull request
Mar 21, 2026
The keyframeIds Set, KEYFRAMES_ID_PREFIX constant, and reconstructWithOptions copy were dropped when rebasing against main (which merged #5696 with a different Sheet.ts).
quantizor
added a commit
that referenced
this pull request
Mar 21, 2026
The keyframeIds Set, KEYFRAMES_ID_PREFIX constant, and reconstructWithOptions copy were dropped when rebasing against main (which merged #5696 with a different Sheet.ts).
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
Rearchitects
createGlobalStyleto use shared stylesheet groups, fixing a recurring bug family spanning 7 years and 5+ issues (#5695, #3146, #3008, #3022, #2769).Root cause: Each mounted instance of a
createGlobalStylecomponent previously allocated its own stylesheet group (componentId + instanceNumber). This coupling between instance lifetime and stylesheet slot lifetime meant any mount/unmount cycle could scatter groups across the stylesheet or orphan them. The bug was "fixed" at least 3 times but kept reappearing.Fix: All instances now share ONE group, registered once at definition time. An
instanceRulescache enables selective removal via clear-and-rebuild.Ordering algorithm
CSS injection order is now fully deterministic:
styled(),createGlobalStyle(), orkeyframes()is called, a group ID is allocated from a global counterChanges
GlobalStyle.ts— shared group withinstanceRulesMap,computeRuleshelper,rebuildGroup(clear + re-insert survivors), rules-equal fast-path to skip CSSOM rebuild when CSS is unchanged, rehydration cache-seeding for static stylesKeyframes.ts— eager group registration viagetGroupForIdin constructor (uses GroupIDAllocator directly to keep native builds DOM-free)createGlobalStyle.ts—useRef-based instance IDs, RSC per-instance style output from cache instead of shared groupBreaking changes
id="sc-global-X1"toid="sc-global-X". Apps upgrading with cached SSR output may see one-time style duplication until caches refresh.Test plan
document.references (DOM isolation verified)Fixes #5695. Fixes #3146. Fixes #3008. Fixes #3022.