From 7ef839a755b966fd49b5cdcd53a830f69a807a21 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Sat, 4 Dec 2021 17:18:22 +0800 Subject: [PATCH] Handle SSG case (ctx.req being undefined) --- pages/_document.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pages/_document.js b/pages/_document.js index 0c241e77..a8e9490d 100644 --- a/pages/_document.js +++ b/pages/_document.js @@ -122,14 +122,16 @@ MyDocument.getInitialProps = async ctx => { const sheets = new ServerStyleSheets(); const originalRenderPage = ctx.renderPage; + // ctx.req will be undefined on static page build + const serverSideCookie = ctx.req?.headers?.cookie + ? cookie.parse(ctx.req.headers.cookie) + : {}; + ctx.renderPage = () => originalRenderPage({ enhanceApp: App => props => sheets.collect( - + ), });