Skip to content

Changed behavior for createGlobalStyle in v6.3.x #5632

Description

@koenpunt

Updating to v6.3.0 did break my global styles. I also see the following warning:

Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.
    at u (/Users/koenpunt/Developer/koenpunt/kakhiel-web-secondary/node_modules/styled-components/src/constructors/createGlobalStyle.ts:32:17)

I think the culprit is here, because I do see a flash of the expected styles, but then those styles are removed.

if (!IS_RSC && typeof React.useLayoutEffect === 'function') {
React.useLayoutEffect(() => {
return () => {
globalStyle.removeStyles(instance, ssc.styleSheet);
};
}, [instance, ssc.styleSheet]);
}

Before the condition was if (!__SERVER__) {, and I think that using the presence of React.useLayoutEffect isn't a reliable check for whether the code is running in a client environment.

I'm using React 18.3.1.

Activity

  1. quantizor commented on Jan 11, 2026

    @quantizor
    Contributor

    Thanks, on it!

  2. mariana-truta-zg commented on Jan 12, 2026

    @mariana-truta-zg

    Hi, unfortunately this issue does not resolve the problem on my side.

    I’m using styled-components v6.3.5 and createGlobalStyle styles are not applied at all (they never appear in the DOM). There are no errors or warnings in the console. I'm using react 19.2.3.

    The same setup worked correctly in v6.2.0. After upgrading to v6.3.x, the global styles are simply missing.

    Could someone please take a look at this?
    Thanks.

  3. floriancargoet commented on Jan 12, 2026

    @floriancargoet

    Similar issue for me. One of my global styles is rendered, the other one is missing.

  4. koenpunt commented on Jan 12, 2026

    @koenpunt
    Author

    For me it initially seemed to work fine with the fix that was applied, although when working on another refactor I did experience some page renders where the globalstyle wasn't applied..

  5. quantizor commented on Jan 12, 2026

    @quantizor
    Contributor

    Thank you for reporting, if there's any additional information you could provide it would be helpful. Even better if someone is able to put together a minimal reproduction? There's a sandbox subproject in this repo that can be used/manipulated to show the problem.

  6. macrozone commented on Jan 13, 2026

    @macrozone

    similar problem, now downgrading to 6.2.0 from 6.3.5.

    i am using multiple global styles, maybe that is the culprit?

    react 19.2.1, nextjs 15.5.4

  7. quantizor commented on Jan 13, 2026

    @quantizor
    Contributor

    Can you please post your react and styled-components versions as well where you're encountering the bug? Really need more info here to help.

  8. mariana-truta-zg commented on Jan 13, 2026

    @mariana-truta-zg

    I have a CodeSandbox with a simple example: https://codesandbox.io/p/sandbox/angry-swartz-n2fhfp. As you can see, it is using styled-components v6.2.0, and the global styles are applied correctly.

    I created another sandbox with the exact same code, but using styled-components v6.3.5:
    https://codesandbox.io/p/sandbox/thirsty-jerry-527tgm. In this version, the global styles are no longer being applied.

    Did anything change in the way global styles should be implemented between these versions?

  9. quantizor commented on Jan 13, 2026

    @quantizor
    Contributor

    Hi, please try out styled-components@prerelease (6.3.7-prerelease.0) and let me know if it helps.

  10. quantizor commented on Jan 13, 2026

    @quantizor
    Contributor

    Updated prerelease to [email protected] with an additional RSC fix

  11. quantizor commented on Jan 13, 2026

    @quantizor
    Contributor

    [email protected] includes one additional improvement for createGlobalStyle when used in conjunction with server-only

  12. quantizor commented on Jan 14, 2026

    @quantizor
    Contributor

    Please like the message if it fixes your issue, thanks.

  13. quantizor commented on Jan 14, 2026

    @quantizor
    Contributor

    One last tweak → [email protected]

    Should fix #5641 which is related to the RSC changes but not this exact issue.

  14. floriancargoet commented on Jan 15, 2026

    @floriancargoet

    It fixes the issue on a simple case (https://codesandbox.io/p/sandbox/styled-components-repro-zgsh57, which didn't work at all with 6.3.5) but it doesn't fix it on my app. I'll try to create a MRE.

  15. floriancargoet commented on Jan 19, 2026

    @floriancargoet

    6.3.8 didn't fix it for me. I'm sorry, I didn't find time to create a MRE.

  16. floriancargoet commented on Jan 19, 2026

    @floriancargoet

    @quantizor
    OK, I identified an easy to reproduce issue, I've updated my codesandbox: https://codesandbox.io/p/sandbox/styled-components-repro-zgsh57

    When the global style component is inside a keyed component (<Component key={key} />), it is not rendered when the key changes.

  17. vitro-gloat commented on Jan 20, 2026

    @vitro-gloat

    @quantizor Version 6.3.8 fixes this issue for me, however it still has #5648 ... Will have to downgrade to 6.2.0 to "solve" both issues.

  18. floriancargoet commented on Feb 9, 2026

    @floriancargoet

    6.3.9 fixes it for me. Thanks!

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

Metadata

Metadata

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