diff --git a/examples/with-styled-components/pages/_document.js b/examples/with-styled-components/pages/_document.js index 5bfaa540..22f5680a 100644 --- a/examples/with-styled-components/pages/_document.js +++ b/examples/with-styled-components/pages/_document.js @@ -4,17 +4,21 @@ import { ServerStyleSheet } from 'styled-components' export default class MyDocument extends Document { static async getInitialProps (ctx) { const sheet = new ServerStyleSheet() - const originalRenderPage = ctx.renderPage - ctx.renderPage = () => - originalRenderPage({ - enhanceApp: App => props => sheet.collectStyles() - }) - const initialProps = await Document.getInitialProps(ctx) - return { - ...initialProps, - styles: [...initialProps.styles, ...sheet.getStyleElement()] + try { + ctx.renderPage = () => + originalRenderPage({ + enhanceApp: App => props => sheet.collectStyles() + }) + + const initialProps = await Document.getInitialProps(ctx) + return { + ...initialProps, + styles: [...initialProps.styles, ...sheet.getStyleElement()] + } + } finally { + sheet.seal() } } }