From 297e4239a9334f66567e24449b9c8e731016699c Mon Sep 17 00:00:00 2001 From: sj0724 Date: Tue, 28 May 2024 19:56:11 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20prerender=EC=8B=9C=EC=A0=90=EC=97=90?= =?UTF-8?q?=EC=84=9C=20css=EB=8F=84=20=ED=8F=AC=ED=95=A8=ED=95=B4=EC=84=9C?= =?UTF-8?q?=20=EB=A0=8C=EB=8D=94=EB=A7=81=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api.ts | 6 +--- pages/_document.tsx | 67 ++++++++++++++++++++++++++++++++++----------- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/api/api.ts b/api/api.ts index 01ef2ed28..66e7d4f7b 100644 --- a/api/api.ts +++ b/api/api.ts @@ -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); diff --git a/pages/_document.tsx b/pages/_document.tsx index 8fbd8fcb0..0c1f3d53f 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -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 ( - - - - - -
- - - - - ); +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(), + }); + + const initialProps = await Document.getInitialProps(ctx); + + return { + ...initialProps, + styles: [ + <> + {initialProps.styles} + {sheet.getStyleElement()} + , + ], + }; + } catch (error) { + throw error; + } finally { + sheet.seal(); + } + } + + render() { + return ( + + + + + +
+ + + + + ); + } } + +export default MyDocument;