Skip to content

Commit 9219aa2

Browse files
authored
Merge pull request #444 from Bamdoliro/feat/#443
레이아웃 쉬프트 현상 수정
2 parents 57bbd1e + ba33fdf commit 9219aa2

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

apps/user/next.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
/** @type {import('next').NextConfig} */
22
module.exports = {
33
transpilePackages: ['@maru/ui'],
4+
compiler: {
5+
styledComponents: true,
6+
},
47
};

apps/user/src/app/layout.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Provider from '@/components/Provider';
2+
import StyledComponentsRegistry from '@/lib/registry';
23
import QueryClientProvider from '@/services/QueryClientProvider';
34
import Script from 'next/script';
45
import { 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
);

apps/user/src/lib/registry.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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;

0 commit comments

Comments
 (0)