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
Hi folks, I have a PR up #5620 that adds a flavor of RSC support to the library by selectively disabling certain incompatible features (like React Context). To test it, install styled-components@prerelease and try removing the 'use client' from the files you're using s-c in.
Please 👍 this post if it works for your setup, if it doesn't then any debugging info you can provide would be very helpful. I just don't have a good complex production test involving RSC + styled-components in my professional sphere at the moment.
I'll leave this up for a while, if it seems like we get a critical mass of 👍 then I'll release it.
Since I don't have any active projects using styled-components at the moment, I opted to test the integration using a fresh create-next-app base. Using Next.js 16.1.1 and Node v22.20.0, I converted the default homepage from CSS Modules to styled-components@prerelease. The entire page rendered server-side perfectly with no FOUC or hydration mismatches. 🚀
I had to prefer styling ahead-of-time to avoid dynamic styles due to server-side serialisation.
For those wanting to avoid hardcoded values while maintaining RSC compatibility, I've found that build-time CSS variable generation (like themizer) works well since it creates static CSS files that work in both Server and Client Components, which would remove the need to implement ThemeProvider (smaller bundle)
@quantizor buddy, just caught it now. I noticed this warning on the server
The component styled.html with the id of "sc-bdfBQy" has been created dynamically.
You may see this warning because you've called styled inside another component.
To resolve this only create new StyledComponents outside of any render method and function component.
See https://styled-components.com/docs/basics#define-styled-components-outside-of-the-render-method for more info.
Thank you for your work on this!
So we are supposed to not have a theme right? When we drop use client. Isn't that confusing? I didn't notice at first, my values where just undefined. It doesn't break, because there is an empty theme object in the props. Maybe it's even better to not have the theme object, so my code will crash, giving me an indicator I have to fix this file.
'server-only';
import CoreButton from '@core/button'; // is a 'use client'
export const Button = styled(CoreButton)`
background-color: black;
`;
this doesn't work properly anymore. Ends up, the specificity lost. This re-styling used to win in specificity (as it was later in the ordering?) but now it's lower. I guess due to from the server injecting losing by order from client rendering of the styles, which come later down the file?
This all starts off working fine, the global styles are added when I open the nav, the context goes to true, the BodyLockStyles is rendered. head now contains: <style data-styled-global="sc-global-krxNsn" data-href="sc-global-sc-global-krxNsn-1-dajaO" data-precedence="styled-components">body{overflow:hidden!important;}/*!sc*/ </style>
Problem is, when I close the nav, this style tag isn't removed.
Activity
Jacksonmills commentedon Jan 6, 2026
Since I don't have any active projects using styled-components at the moment, I opted to test the integration using a fresh create-next-app base. Using Next.js 16.1.1 and Node v22.20.0, I converted the default homepage from CSS Modules to
styled-components@prerelease. The entire page rendered server-side perfectly with no FOUC or hydration mismatches. 🚀quantizor commentedon Jan 6, 2026
@Jacksonmills so good to see you around, thank you for testing it 😁
soujvnunes commentedon Jan 9, 2026
I've tested
styled-components@prereleasewith Next.js and can confirm it works!I removed
'use client'from component files using styled-components and the server component rendering them have no FOUC or hydration issues:Just some notes I'd document:
ThemeProvider(smaller bundle)quantizor commentedon Jan 10, 2026
@soujvnunes thank you, great callout. I will add content for this to the release notes and FAQ!
quantizor commentedon Jan 10, 2026
Shipping this tonight, thank you testers!
soujvnunes commentedon Jan 10, 2026
@quantizor buddy, just caught it now. I noticed this warning on the server
quantizor commentedon Jan 10, 2026
@soujvnunes any chance you could share code samples around the component giving you issues?
soujvnunes commentedon Jan 10, 2026
Sure
https://codesandbox.io/p/devbox/qk5y5d
quantizor commentedon Jan 10, 2026
Cool, thanks! I think it's a false positive. Will fix.
quantizor commentedon Jan 10, 2026
Thanks for your help again! https://github.com/styled-components/styled-components/releases/tag/styled-components%406.3.3
laurenskling commentedon Jan 12, 2026
Thank you for your work on this!
So we are supposed to not have a
themeright? When we dropuse client. Isn't that confusing? I didn't notice at first, my values where just undefined. It doesn't break, because there is an emptythemeobject in the props. Maybe it's even better to not have thethemeobject, so my code will crash, giving me an indicator I have to fix this file.laurenskling commentedon Jan 12, 2026
I've hit a use case:
this doesn't work properly anymore. Ends up, the specificity lost. This re-styling used to win in specificity (as it was later in the ordering?) but now it's lower. I guess due to from the server injecting losing by order from client rendering of the styles, which come later down the file?
laurenskling commentedon Jan 12, 2026
I have this:
I use it for my nav:
using this trick wrapper I created to read context:
This all starts off working fine, the global styles are added when I open the nav, the context goes to true, the BodyLockStyles is rendered. head now contains:
<style data-styled-global="sc-global-krxNsn" data-href="sc-global-sc-global-krxNsn-1-dajaO" data-precedence="styled-components">body{overflow:hidden!important;}/*!sc*/ </style>Problem is, when I close the nav, this style tag isn't removed.