Skip to content

Commit

Permalink
fix: prerender시점에서 css도 포함해서 렌더링하도록 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
sj0724 committed May 28, 2024
1 parent 1015c20 commit 297e423
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 21 deletions.
6 changes: 1 addition & 5 deletions api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,7 @@ export async function postFolder(name: string) {
export async function deleteFolder(folderId: string) {
try {
const token = localStorage.getItem('token');
const { data } = await axios.delete(`/folders/${folderId}`, {
headers: {
Authorization: token,
},
});
const { data } = await axios.delete(`/folders/${folderId}`);
return data;
} catch (error) {
console.error('Error fetching post folder:', error);
Expand Down
67 changes: 51 additions & 16 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
import { Html, Head, Main, NextScript } from 'next/document';
import Document, { DocumentContext } from 'next/document';
import { ServerStyleSheet } from 'styled-components';

export default function Document() {
return (
<Html lang="ko">
<Head>
<script
defer
src="https://developers.kakao.com/sdk/js/kakao.min.js"
></script>
</Head>
<body>
<Main />
<NextScript />
<div id="modal"></div>
</body>
</Html>
);
class MyDocument extends Document {
static async getInitialProps(ctx: DocumentContext) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage;

try {
ctx.renderPage = () =>
originalRenderPage({
enhanceApp: (App) => (props) =>
sheet.collectStyles(<App {...props} />),
});

const initialProps = await Document.getInitialProps(ctx);

return {
...initialProps,
styles: [
<>
{initialProps.styles}
{sheet.getStyleElement()}
</>,
],
};
} catch (error) {
throw error;
} finally {
sheet.seal();
}
}

render() {
return (
<Html lang="ko">
<Head>
<script
defer
src="https://developers.kakao.com/sdk/js/kakao.min.js"
></script>
</Head>
<body>
<Main />
<NextScript />
<div id="modal"></div>
</body>
</Html>
);
}
}

export default MyDocument;

0 comments on commit 297e423

Please sign in to comment.