/* eslint-disable */ import React from 'react'; import PropTypes from 'prop-types'; import cookies from 'next-cookies'; // @ts-ignore import flush from 'styled-jsx/server'; import Document, { Head, Main, NextScript, NextDocumentContext } from 'next/document'; import { prismThemes } from '../utils/prism'; import { ThemeType } from 'layout/PageWithContext'; import { PageContext } from '../utils/getPageContext'; class MyDocument extends Document<{ theme?: ThemeType }> { static getInitialProps = (ctx: NextDocumentContext) => { // Render app and page and get the context of the page with collected side effects. let pageContext: PageContext | undefined; const { theme } = cookies(ctx as any); const page = ctx.renderPage((Component) => { const WrappedComponent = (props: any) => { pageContext = props.pageContext; return ; }; WrappedComponent.propTypes = { pageContext: PropTypes.object.isRequired, }; return WrappedComponent; }); let css: string; // It might be undefined, e.g. after an error. if (pageContext) { css = pageContext.sheetsRegistry.toString(); } return { ...page, theme, pageContext, // Styles fragment is rendered after the app and page rendering finish. styles: (