Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('aphrodite')
7 changes: 5 additions & 2 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ export default class Document extends Component {
}

export function Head (props, context) {
const { head } = context._documentProps
const { head, css } = context._documentProps
const h = (head || [])
.map((h, i) => React.cloneElement(h, { key: '_next' + i }))
return <head>{h}</head>
return <head>
{h}
<style data-aphrodite>{css.content}</style>
</head>
}

Head.contextTypes = { _documentProps: PropTypes.any }
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test": "ava"
},
"dependencies": {
"aphrodite": "0.5.0",
"babel-core": "6.17.0",
"babel-generator": "6.17.0",
"babel-loader": "6.2.5",
Expand Down Expand Up @@ -41,6 +42,7 @@
},
"devDependencies": {
"ava": "0.16.0",
"del": "2.2.2",
"gulp": "3.9.1",
"gulp-babel": "6.1.2",
"gulp-cached": "1.1.0",
Expand Down
16 changes: 11 additions & 5 deletions server/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import fs from 'mz/fs'
import Document from '../lib/document'
import App from '../lib/app'
import { StyleSheetServer } from '../lib/css'

export async function render (path, req, res, { root = process.cwd() } = {}) {
const mod = require(resolve(root, '.next', 'pages', path)) || {}
Expand All @@ -17,15 +18,20 @@ export async function render (path, req, res, { root = process.cwd() } = {}) {
const bundlePath = resolve(root, '.next', '.next', 'pages', path || 'index.js')
const component = await fs.readFile(bundlePath, 'utf8')

const app = createElement(App, {
Component,
props,
router: {}
const { html, css } = StyleSheetServer.renderStatic(() => {
const app = createElement(App, {
Component,
props,
router: {}
})

return renderToString(app)
})

const doc = createElement(Document, {
head: [],
html: renderToString(app),
html: html,
css: css,
data: { component },
hotReload: false
})
Expand Down