Skip to content

Commit

Permalink
Fix styled-components setup in turbo example (#44165)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
huozhi committed Dec 19, 2022
1 parent 43c9d89 commit ea7d856
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion examples/with-turbopack/lib/styling.tsx
Expand Up @@ -9,11 +9,12 @@ export function useStyledComponentsRegistry() {

const styledComponentsFlushEffect = () => {
const styles = styledComponentsStyleSheet.getStyleElement();
styledComponentsStyleSheet.seal();
styledComponentsStyleSheet.instance.clearTag();
return <>{styles}</>;
};

function StyledComponentsRegistry({ children }: ChildProps) {
if (typeof window !== 'undefined') return <>{children}</>;
return (
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
{children as React.ReactChild}
Expand Down
14 changes: 10 additions & 4 deletions test/e2e/app-dir/rsc-basic/app/root-style-registry.js
Expand Up @@ -29,9 +29,15 @@ export default function RootStyleRegistry({ children }) {
return <>{styledComponentsFlushEffect()}</>
})

return (
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
<StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry>
</StyleSheetManager>
const child = (
<StyleRegistry registry={jsxStyleRegistry}>{children}</StyleRegistry>
)
if (typeof window === 'undefined') {
return (
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
{child}
</StyleSheetManager>
)
}
return child
}

0 comments on commit ea7d856

Please sign in to comment.