Skip to content

Commit

Permalink
Merge pull request #458 from cofacts/fix-build
Browse files Browse the repository at this point in the history
Handle SSG case
  • Loading branch information
MrOrz authored Dec 4, 2021
2 parents 20c9b0b + 7ef839a commit 7306375
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pages/_document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<App
{...props}
serverSideCookie={cookie.parse(ctx.req.headers.cookie)}
/>
<App {...props} serverSideCookie={serverSideCookie} />
),
});

Expand Down

0 comments on commit 7306375

Please sign in to comment.