Repository navigation
Conversation
🦋 Changeset detectedLatest commit: 1791950 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 |
federico-fiorini
marked this pull request as ready for review
January 30, 2026 11:32
- Pass insertion target to removeGlobalStyleTag so it queries the correct container (ShadowRoot or document) when cleaning up SSR-rendered global style tags on unmount - Use tag.getRootNode() in getSheet fallback so the Firefox quirk path checks the shadow root's styleSheets instead of only document.styleSheets - Add tests for both fixes and getSheet/makeStyleTag in shadow DOM Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
|
@federico-fiorini thank you for this! |
quantizor
approved these changes
Feb 8, 2026
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.
Fix: Shadow DOM SSR Hydration Support
Problem
Styled-components' SSR hydration does not work in Shadow DOM contexts, causing complete hydration failure and duplicate style injection.
Issue 1: Hardcoded
documentSearchThe
rehydrateSheet()function only searchesdocument.querySelectorAll()for server-rendered styles, making it unable to find styles rendered inside Shadow DOM.Current behavior:
documentfor these styles<style>tagsIssue 2:
SHOULD_REHYDRATEFlag Prevents Re-rehydrationThe global
SHOULD_REHYDRATEflag is set tofalseafter the first rehydration attempt, preventing subsequent rehydration when the target changes.Common pattern that fails:
What happens:
targetisundefined→ rehydrates fromdocument(finds nothing)SHOULD_REHYDRATEflag set tofalseuseLayoutEffect:targetchanges toshadowRootStyleSheetManagercallsreconstructWithOptions({ target: shadowRoot })Solution
1. Container Detection Helper
Added
getRehydrationContainer()helper that extracts the correct container (Document or ShadowRoot) from anInsertionTarget:2. Updated
rehydrateSheet()SignatureSimplified to accept only the
sheetparameter and extract the target fromsheet.options.target:3. Re-rehydration on Container Change
Updated
reconstructWithOptions()to detect when the target's container changes and trigger rehydration:Changes
src/sheet/Rehydration.ts: Added exportedgetRehydrationContainer()helper and updatedrehydrateSheet()to use itsrc/sheet/Sheet.ts: Updated constructor,rehydrate(), andreconstructWithOptions()to use container-based rehydrationsrc/sheet/test/Rehydration.test.tsx: Added 8 tests for Shadow DOM rehydrationsrc/sheet/test/Sheet.test.ts: Added 3 tests forreconstructWithOptions()with target/container changesBenefits
documentwhen no target specified)Testing
All 44 tests passing, including comprehensive Shadow DOM coverage:
Rehydration Tests (8 tests)
Sheet Tests (3 tests)