Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
material-ui/examples/nextjs/pages/_document.js /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
79 lines (74 sloc)
2.11 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
import * as React from 'react'; | |
import Document, { Head, Main, NextScript } from 'next/document'; | |
import { getContext, setContext } from '../styles/context'; | |
class MyDocument extends Document { | |
render() { | |
const context = getContext(); | |
return ( | |
<html lang="en" dir="ltr"> | |
<Head> | |
<title>My page</title> | |
<meta charSet="utf-8" /> | |
{/* Use minimum-scale=1 to enable GPU rasterization */} | |
<meta | |
name="viewport" | |
content={ | |
'user-scalable=0, initial-scale=1, ' + | |
'minimum-scale=1, width=device-width, height=device-height' | |
} | |
/> | |
{/* | |
manifest.json provides metadata used when your web app is added to the | |
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ | |
*/} | |
<link rel="manifest" href="/static/manifest.json" /> | |
{/* PWA primary color */} | |
<meta name="theme-color" content={context.theme.palette.primary[500]} /> | |
<link | |
rel="stylesheet" | |
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" | |
/> | |
</Head> | |
<body> | |
<Main /> | |
<NextScript /> | |
</body> | |
</html> | |
); | |
} | |
} | |
MyDocument.getInitialProps = ctx => { | |
// Resolution order | |
// | |
// On the server: | |
// 1. page.getInitialProps | |
// 2. document.getInitialProps | |
// 3. page.render | |
// 4. document.render | |
// | |
// On the server with error: | |
// 2. document.getInitialProps | |
// 3. page.render | |
// 4. document.render | |
// | |
// On the client | |
// 1. page.getInitialProps | |
// 3. page.render | |
// Reset the context for handling a new request. | |
setContext(); | |
const page = ctx.renderPage(); | |
// Get the context with the collected side effects. | |
const context = getContext(); | |
return { | |
...page, | |
styles: ( | |
<style | |
id="jss-server-side" | |
// eslint-disable-next-line react/no-danger | |
dangerouslySetInnerHTML={{ __html: context.sheetsRegistry.toString() }} | |
/> | |
), | |
}; | |
}; | |
export default MyDocument; |