Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

레이아웃 쉬프트 현상 수정 #444

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/user/next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/** @type {import('next').NextConfig} */
module.exports = {
transpilePackages: ['@maru/ui'],
compiler: {
styledComponents: true,
},
};
9 changes: 6 additions & 3 deletions apps/user/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Provider from '@/components/Provider';
import StyledComponentsRegistry from '@/lib/registry';
import QueryClientProvider from '@/services/QueryClientProvider';
import Script from 'next/script';
import { ReactNode } from 'react';
Expand Down Expand Up @@ -30,9 +31,11 @@ const Layout = ({ children }: Props) => {
</Script>
</head>
<body>
<QueryClientProvider>
<Provider>{children}</Provider>
</QueryClientProvider>
<StyledComponentsRegistry>
<QueryClientProvider>
<Provider>{children}</Provider>
</QueryClientProvider>
</StyledComponentsRegistry>
</body>
</html>
);
Expand Down
29 changes: 29 additions & 0 deletions apps/user/src/lib/registry.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use client';

import { useServerInsertedHTML } from 'next/navigation';
import { ReactNode, useState } from 'react';
import { ServerStyleSheet, StyleSheetManager } from 'styled-components';

interface Props {
children: ReactNode;
}

const StyledComponentsRegistry = ({ children }: Props) => {
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet());

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

if (typeof window !== 'undefined') return <>{children}</>;

return (
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}>
{children}
</StyleSheetManager>
);
};

export default StyledComponentsRegistry;