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
in development, updating a createGlobalStyle doesn't remove the old version #5641
If I remove the ThemeProvider the error is still, useRef only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-component
The SSR starts with a big data-href server version of the globalstyle.
When I add background-color: green; to my body, you see a second style tag. The I change to blue, third style tag. Then I remove that line, make it go back to the background-color: white;, a fourth shows up (note that this is the same css as the SSRed)
I change to width: 25%, fifth style tag. I remove it again. No new style tag. Here it sees that this version of the styles are already rendered in the fourth style tag. This is where the bug shines. I removed the width, but it's still in my browser. next: width: 40%, sixth style tag. Remove that again. Again, it sees that we already have this version of the styles, so no new tag, but we remain at 40%.
I have a server-onlycreateGlobalStyle, which I conditionally render in a use client. These styles are added when the render happens, but not removed when the render removes it. I've already wrote about this. It's basically the same bug I guess.
When I put this createGlobalStyle in a use client, it works as expected. The style line goes in and out of <style data-styled="active" data-styled-version="6.3.7-prerelease.2">
As you made them in "regular" react component (or something like this I read somewhere in your comments). They seem to be rendered in the tree at the spot you put the tag. Which makes sense. But I guess not what you'd want.
Is it the precedence that made it go to the head before?
The original bug (global styles not being removed during HMR) was fixed in 6.3.9.
Regarding the remaining note about server-only createGlobalStyle rendering <style> tags in the body instead of <head>: this is a known limitation of RSC mode. Without React 19's precedence attribute (which we intentionally avoid for global styles due to unmount persistence issues), there's no mechanism for React to hoist the tag to <head> during streaming.
Workaround: If you need global styles in <head>, use the 'use client' + StyledComponentsRegistry pattern.
No other runtime CSS-in-JS library has solved this — Emotion doesn't support RSC at all, and zero-runtime libraries (Pigment CSS, Panda, vanilla-extract) sidestep it with build-time extraction. We'll revisit when React provides better primitives for style injection during streaming.
Activity
quantizor commentedon Jan 13, 2026
Related to #5632
quantizor commentedon Jan 13, 2026
Hi, please try out
styled-components@prerelease(6.3.7-prerelease.0) and let me know if it helps.laurenskling commentedon Jan 13, 2026
That release gets me stuck on:
the full file it's (now) crashing on:
laurenskling commentedon Jan 13, 2026
If I remove the ThemeProvider the error is still,
useRef only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/react-client-hook-in-server-componentquantizor commentedon Jan 13, 2026
That's to be expected,
ThemeProvideruses React context which is not available under RSCquantizor commentedon Jan 13, 2026
I'll check into the useRef usage, I wasn't aware that particular hook is not available in RSC.
laurenskling commentedon Jan 13, 2026
It's a No-op in 6.3.x RSC remember ;) But it was a false flag. I debugged it down to the
<GlobalStyle />in my codequantizor commentedon Jan 13, 2026
Ok try [email protected]
laurenskling commentedon Jan 13, 2026
sadly still the case
quantizor commentedon Jan 13, 2026
How? Are you sure the new version is installed? The hook usage is physically guarded now inside the
!IS_RSCcheck...laurenskling commentedon Jan 13, 2026
I'm sorry, I ment the original bug report, not the useRef thingy
laurenskling commentedon Jan 13, 2026
quantizor commentedon Jan 13, 2026
Any chance you could share the code snippets for those and the SSR styled-components registry snippet?
[email protected]has a candidate fix for the original dev issue you mentionedlaurenskling commentedon Jan 14, 2026
laurenskling commentedon Jan 14, 2026
Schermopname.2026-01-14.om.09.46.16.mov
The SSR starts with a big
data-hrefserver version of the globalstyle.When I add
background-color: green;to my body, you see a second style tag. The I change to blue, third style tag. Then I remove that line, make it go back to thebackground-color: white;, a fourth shows up (note that this is the same css as the SSRed)I change to
width: 25%, fifth style tag. I remove it again. No new style tag. Here it sees that this version of the styles are already rendered in the fourth style tag. This is where the bug shines. I removed the width, but it's still in my browser. next:width: 40%, sixth style tag. Remove that again. Again, it sees that we already have this version of the styles, so no new tag, but we remain at 40%.laurenskling commentedon Jan 14, 2026
I have a
server-onlycreateGlobalStyle, which I conditionally render in ause client. These styles are added when the render happens, but not removed when the render removes it. I've already wrote about this. It's basically the same bug I guess.When I put this
createGlobalStylein ause client, it works as expected. The style line goes in and out of<style data-styled="active" data-styled-version="6.3.7-prerelease.2">quantizor commentedon Jan 14, 2026
Could you try out
[email protected]when you get a moment?laurenskling commentedon Jan 15, 2026
They are still never removed. I think I know why:
https://github.com/styled-components/styled-components/pull/5638/files#diff-b8702cbcaf39eaa95deb156bf4132fef9fd7096c4f87679cf656105070c38bc8R88
this is the line that does the removing right? It is inside the
!IS_RSCcheck ofGlobalStyleComponent. You would think: that will be true on the client, so it works. But I don't see this code being executed on the client. I'm not an expert on RSC, But I believe that there is no client mounting going on when it's not marked asuse client, so this code is not hydrated, it is not run. ThisuseLayoutEffecthook is never added to the Node.laurenskling commentedon Jan 19, 2026
This issue persists in
6.3.8quantizor commentedon Feb 7, 2026
Fixing in the next version
quantizor commentedon Feb 8, 2026
Please try 6.3.9 https://github.com/styled-components/styled-components/releases/tag/styled-components%406.3.9
laurenskling commentedon Feb 8, 2026
In 6.3.9 global styles are unmounted and re-added with a new
data-styled-globaltag, thus working. Thank you.Just a note: global styles are now rendered in the
body, not in thehead. This is as intended?quantizor commentedon Feb 8, 2026
Ah, thanks for reporting. No should probably be in the head. Will look later, or if you have time would welcome a PR!
laurenskling commentedon Feb 8, 2026
As you made them in "regular" react component (or something like this I read somewhere in your comments). They seem to be rendered in the tree at the spot you put the tag. Which makes sense. But I guess not what you'd want.
Is it the
precedencethat made it go to theheadbefore?quantizor commentedon Mar 19, 2026
The original bug (global styles not being removed during HMR) was fixed in 6.3.9.
Regarding the remaining note about server-only
createGlobalStylerendering<style>tags in the body instead of<head>: this is a known limitation of RSC mode. Without React 19'sprecedenceattribute (which we intentionally avoid for global styles due to unmount persistence issues), there's no mechanism for React to hoist the tag to<head>during streaming.Workaround: If you need global styles in
<head>, use the'use client'+StyledComponentsRegistrypattern.No other runtime CSS-in-JS library has solved this — Emotion doesn't support RSC at all, and zero-runtime libraries (Pigment CSS, Panda, vanilla-extract) sidestep it with build-time extraction. We'll revisit when React provides better primitives for style injection during streaming.