File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 11/** @type {import('next').NextConfig } */
22module . exports = {
33 transpilePackages : [ '@maru/ui' ] ,
4+ compiler : {
5+ styledComponents : true ,
6+ } ,
47} ;
Original file line number Diff line number Diff line change 11import Provider from '@/components/Provider' ;
2+ import StyledComponentsRegistry from '@/lib/registry' ;
23import QueryClientProvider from '@/services/QueryClientProvider' ;
34import Script from 'next/script' ;
45import { ReactNode } from 'react' ;
@@ -30,9 +31,11 @@ const Layout = ({ children }: Props) => {
3031 </ Script >
3132 </ head >
3233 < body >
33- < QueryClientProvider >
34- < Provider > { children } </ Provider >
35- </ QueryClientProvider >
34+ < StyledComponentsRegistry >
35+ < QueryClientProvider >
36+ < Provider > { children } </ Provider >
37+ </ QueryClientProvider >
38+ </ StyledComponentsRegistry >
3639 </ body >
3740 </ html >
3841 ) ;
Original file line number Diff line number Diff line change 1+ 'use client' ;
2+
3+ import { useServerInsertedHTML } from 'next/navigation' ;
4+ import { ReactNode , useState } from 'react' ;
5+ import { ServerStyleSheet , StyleSheetManager } from 'styled-components' ;
6+
7+ interface Props {
8+ children : ReactNode ;
9+ }
10+
11+ const StyledComponentsRegistry = ( { children } : Props ) => {
12+ const [ styledComponentsStyleSheet ] = useState ( ( ) => new ServerStyleSheet ( ) ) ;
13+
14+ useServerInsertedHTML ( ( ) => {
15+ const styles = styledComponentsStyleSheet . getStyleElement ( ) ;
16+ styledComponentsStyleSheet . instance . clearTag ( ) ;
17+ return < > { styles } </ > ;
18+ } ) ;
19+
20+ if ( typeof window !== 'undefined' ) return < > { children } </ > ;
21+
22+ return (
23+ < StyleSheetManager sheet = { styledComponentsStyleSheet . instance } >
24+ { children }
25+ </ StyleSheetManager >
26+ ) ;
27+ } ;
28+
29+ export default StyledComponentsRegistry ;
You can’t perform that action at this time.
0 commit comments