Unverified Commit ea7d8568 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Fix styled-components setup in turbo example (#44165)

Closes: #44164

Sync to the latest setup doc on https://beta.nextjs.org/docs/styling/css-in-js#styled-components

## Documentation / Examples

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [x] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent 43c9d894
...@@ -9,11 +9,12 @@ export function useStyledComponentsRegistry() { ...@@ -9,11 +9,12 @@ export function useStyledComponentsRegistry() {
const styledComponentsFlushEffect = () => { const styledComponentsFlushEffect = () => {
const styles = styledComponentsStyleSheet.getStyleElement(); const styles = styledComponentsStyleSheet.getStyleElement();
styledComponentsStyleSheet.seal(); styledComponentsStyleSheet.instance.clearTag();
return <>{styles}</>; return <>{styles}</>;
}; };
function StyledComponentsRegistry({ children }: ChildProps) { function StyledComponentsRegistry({ children }: ChildProps) {
if (typeof window !== 'undefined') return <>{children}</>;
return ( return (
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}> <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
{children as React.ReactChild} {children as React.ReactChild}
......
...@@ -29,9 +29,15 @@ export default function RootStyleRegistry({ children }) { ...@@ -29,9 +29,15 @@ export default function RootStyleRegistry({ children }) {
return <>{styledComponentsFlushEffect()}</> return <>{styledComponentsFlushEffect()}</>
}) })
const child = (
<StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry>
)
if (typeof window === 'undefined') {
return ( return (
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}> <StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
<StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry> {child}
</StyleSheetManager> </StyleSheetManager>
) )
}
return child
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment