File tree Expand file tree Collapse file tree 4 files changed +66
-5
lines changed Expand file tree Collapse file tree 4 files changed +66
-5
lines changed Original file line number Diff line number Diff line change 1
- import Provider from "@/provider/provider.helper" ;
1
+ import Provider from "@/provider/Provider.helper" ;
2
+ import ServerStyleProvider from "@/provider/ServerStyleProvider" ;
2
3
3
4
export const metadata = {
4
5
title : "BSM" ,
@@ -13,7 +14,9 @@ export default function RootLayout({
13
14
return (
14
15
< html lang = "en" >
15
16
< body >
16
- < Provider > { children } </ Provider >
17
+ < Provider >
18
+ < ServerStyleProvider > { children } </ ServerStyleProvider >
19
+ </ Provider >
17
20
</ body >
18
21
</ html >
19
22
) ;
Original file line number Diff line number Diff line change
1
+ "use client" ;
2
+
3
+ import React , { useState } from "react" ;
4
+ import { useServerInsertedHTML } from "next/navigation" ;
5
+ import { ServerStyleSheet , StyleSheetManager } from "styled-components" ;
6
+
7
+ export default function ServerStyleProvider ( {
8
+ children,
9
+ } : {
10
+ children : React . ReactNode ;
11
+ } ) {
12
+ // Only create stylesheet once with lazy initial state
13
+ // x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
14
+ const [ styledComponentsStyleSheet ] = useState ( ( ) => new ServerStyleSheet ( ) ) ;
15
+
16
+ useServerInsertedHTML ( ( ) => {
17
+ const styles = styledComponentsStyleSheet . getStyleElement ( ) ;
18
+ styledComponentsStyleSheet . instance . clearTag ( ) ;
19
+ // eslint-disable-next-line
20
+ return < > { styles } </ > ;
21
+ } ) ;
22
+
23
+ // eslint-disable-next-line
24
+ if ( typeof window !== "undefined" ) return < > { children } </ > ;
25
+
26
+ return (
27
+ < StyleSheetManager sheet = { styledComponentsStyleSheet . instance } >
28
+ { children }
29
+ </ StyleSheetManager >
30
+ ) ;
31
+ }
Original file line number Diff line number Diff line change
1
+ import React from "react" ;
2
+ import { ServerStyleSheet , StyleSheetManager } from "styled-components" ;
3
+
4
+ export function useStyledComponentsRegistry ( ) {
5
+ const [ styledComponentsStyleSheet ] = React . useState (
6
+ ( ) => new ServerStyleSheet ( ) ,
7
+ ) ;
8
+
9
+ const styledComponentsFlushEffect = ( ) => {
10
+ const styles = styledComponentsStyleSheet . getStyleElement ( ) ;
11
+ styledComponentsStyleSheet . instance . clearTag ( ) ;
12
+ // eslint-disable-next-line
13
+ return < > { styles } </ > ;
14
+ } ;
15
+
16
+ const StyledComponentsProvider = ( {
17
+ children,
18
+ } : {
19
+ children : React . ReactNode ;
20
+ } ) => (
21
+ < StyleSheetManager sheet = { styledComponentsStyleSheet . instance } >
22
+ { children as React . ReactElement }
23
+ </ StyleSheetManager >
24
+ ) ;
25
+
26
+ return [ StyledComponentsProvider , styledComponentsFlushEffect ] as const ;
27
+ }
Original file line number Diff line number Diff line change 2
2
3
3
import React from "react" ;
4
4
import { RecoilRoot } from "recoil" ;
5
- import ReactQueryProvider from "./reactQueryProvider .helper" ;
6
- import LayoutProvider from "./layoutProvider .helper" ;
7
- import ApolloClientProvider from "./apolloClientProvider .helper" ;
5
+ import ReactQueryProvider from "./ReactQueryProvider .helper" ;
6
+ import ApolloClientProvider from "./ApolloClientProvider .helper" ;
7
+ import LayoutProvider from "./LayoutProvider .helper" ;
8
8
9
9
const Provider = ( { children } : React . PropsWithChildren ) => {
10
10
return (
You can’t perform that action at this time.
0 commit comments