mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
![Tim Neutkens](/assets/img/avatar_default.png)
* Remove traces of glamor As talked about with @rauchg. Glamor takes up around 60KB of the bundle (pre-gzip). Since styled-jsx is the way to go now and we support adding glamor by the user we should remove it as dependency cause it is bundled even when not used. Added rehydration to the example, since we did that in our code. There is only one thing I'm not sure about and want to discuss: what should we do with next/css. Right now I added a throw for when it is imported. I'm not sure if we should do that / some other way to notify the user it has been removed. The reasoning behind the throw is that when we would do a console.warn the user would see 'css.default.<X>' not found because we don't have the glamor dependency anymore. * Update yarn.lock * Remove test for styles
75 lines
1.8 KiB
JavaScript
75 lines
1.8 KiB
JavaScript
import React, { Component, PropTypes } from 'react'
|
|
import htmlescape from 'htmlescape'
|
|
import flush from 'styled-jsx/server'
|
|
|
|
export default class Document extends Component {
|
|
static getInitialProps ({ renderPage }) {
|
|
const {html, head} = renderPage()
|
|
const styles = flush()
|
|
return { html, head, styles }
|
|
}
|
|
|
|
static childContextTypes = {
|
|
_documentProps: PropTypes.any
|
|
}
|
|
|
|
getChildContext () {
|
|
return { _documentProps: this.props }
|
|
}
|
|
|
|
render () {
|
|
return <html>
|
|
<Head />
|
|
<body>
|
|
<Main />
|
|
<NextScript />
|
|
</body>
|
|
</html>
|
|
}
|
|
}
|
|
|
|
export class Head extends Component {
|
|
static contextTypes = {
|
|
_documentProps: PropTypes.any
|
|
}
|
|
|
|
render () {
|
|
const { head, styles } = this.context._documentProps
|
|
return <head>
|
|
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))}
|
|
{styles || null}
|
|
{this.props.children}
|
|
</head>
|
|
}
|
|
}
|
|
|
|
export class Main extends Component {
|
|
static contextTypes = {
|
|
_documentProps: PropTypes.any
|
|
}
|
|
|
|
render () {
|
|
const { html } = this.context._documentProps
|
|
return <div id='__next' dangerouslySetInnerHTML={{ __html: html }} />
|
|
}
|
|
}
|
|
|
|
export class NextScript extends Component {
|
|
static contextTypes = {
|
|
_documentProps: PropTypes.any
|
|
}
|
|
|
|
render () {
|
|
const { staticMarkup, __NEXT_DATA__ } = this.context._documentProps
|
|
let { buildId } = __NEXT_DATA__
|
|
|
|
return <div>
|
|
{staticMarkup ? null : <script dangerouslySetInnerHTML={{
|
|
__html: `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)}; module={};`
|
|
}} />}
|
|
{ staticMarkup ? null : <script type='text/javascript' src={`/_next/${buildId}/commons.js`} /> }
|
|
{ staticMarkup ? null : <script type='text/javascript' src={`/_next/${buildId}/main.js`} /> }
|
|
</div>
|
|
}
|
|
}
|