Skip to content

RSC Re-styling of a client component loses by specificity #5672

Closed

Description

@laurenskling

Mentioned before in: #5624 (comment)

in 6.3.11 this still happens.

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.

Activity

  1. quantizor commented on Mar 19, 2026

    @quantizor
    Contributor

    Confirmed — this is an architectural ordering conflict between two independent style injection mechanisms:

    1. RSC path: Emits <style precedence="styled-components"> tags that React 19 hoists into <head> as permanent resources
    2. 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
    • Using CSS @layer for cascade control
  2. quantizor commented on Mar 21, 2026

    @quantizor
    Contributor

    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 @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.

    Please test and report back — install with npm i [email protected].

  3. quantizor commented on Mar 23, 2026

    @quantizor
    Contributor

    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.

  4. laurenskling commented on Mar 31, 2026

    @laurenskling
    Author

    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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions