You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RSC Re-styling of a client component loses by specificity #5672
If I const ServerButton = styled(ClientButton)`` , a .jCHQcn is created for ServerButton which is included in the <style data-precedence="styled-components" data-href=... style tag on the page, with all the server styles.
But, ClientButton created .iMMMst, which is included in the client scraped styles which are in the <style data-styled="active" data-styled-version="6.3.11"> tag near the end of the head.
This ends up in the ClientButton winning in specificity, because it's further down the document. Making my re-styles lose and not work.
Confirmed — this is an architectural ordering conflict between two independent style injection mechanisms:
RSC path: Emits <style precedence="styled-components"> tags that React 19 hoists into <head> as permanent resources
Client path: During hydration, injects styles into <style data-styled="active"> which is appended after the RSC tags
Since both selectors have equal specificity (single class), the client-injected base styles win by document order, overriding the RSC override styles. This doesn't happen in pure-client or pure-server scenarios because those use a single injection mechanism with coordinated ordering.
Potential approaches:
Specificity bumping for RSC overrides of non-styled targets (double the class selector)
Unifying both paths into the same injection system
RSC components extending client components now correctly override base styles via plain inline <style> tags with :where() zero-specificity wrapping on base CSS. Keyframe IDs are also deduplicated to prevent duplicate @keyframes rules in SSR output.
See the staged Version Packages PR #5687 for the full changelog, including the new createTheme CSS variable utility and createGlobalStyle shared-group rearchitecture.
Confirmed fixed in 6.4.0-prerelease.3+ via :where() zero-specificity wrapping on base CSS in RSC inheritance chains. 54 tests covering this scenario all pass, including adversarial fuzzing.
Available now via npm i styled-components@test. See PR #5687 for the full changelog.
Yes, inline style tags will take specificity over the head style tag created by the client registry.
What do you mean with ":where() zero-specificity wrapping on base CSS"? I'm sorry for not understanding this. Is that something SC will do or I should do?
Activity
quantizor commentedon Mar 19, 2026
Confirmed — this is an architectural ordering conflict between two independent style injection mechanisms:
<style precedence="styled-components">tags that React 19 hoists into<head>as permanent resources<style data-styled="active">which is appended after the RSC tagsSince both selectors have equal specificity (single class), the client-injected base styles win by document order, overriding the RSC override styles. This doesn't happen in pure-client or pure-server scenarios because those use a single injection mechanism with coordinated ordering.
Potential approaches:
@layerfor cascade controlquantizor commentedon Mar 21, 2026
This is fixed in
[email protected](now published on npm).RSC components extending client components now correctly override base styles via plain inline
<style>tags with:where()zero-specificity wrapping on base CSS. Keyframe IDs are also deduplicated to prevent duplicate@keyframesrules in SSR output.See the staged Version Packages PR #5687 for the full changelog, including the new
createThemeCSS variable utility andcreateGlobalStyleshared-group rearchitecture.Please test and report back — install with
npm i [email protected].quantizor commentedon Mar 23, 2026
Confirmed fixed in 6.4.0-prerelease.3+ via
:where()zero-specificity wrapping on base CSS in RSC inheritance chains. 54 tests covering this scenario all pass, including adversarial fuzzing.Available now via
npm i styled-components@test. See PR #5687 for the full changelog.laurenskling commentedon Mar 31, 2026
Yes, inline style tags will take specificity over the head style tag created by the client registry.
What do you mean with ":where() zero-specificity wrapping on base CSS"? I'm sorry for not understanding this. Is that something SC will do or I should do?
fix: emit RSC styles per instance so they survive Suspense reveals (#…