Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b89351

Browse files
Groklingtimneutkens
authored andcommitted
Add SSR to examples/with-styled-components + bump styled_components v2 (vercel#1908)
1 parent 12f423f commit 1b89351

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"presets": [
3+
"next/babel",
4+
"stage-0"
5+
],
6+
"plugins": [
7+
["styled-components", { "ssr": true, "displayName": true, "preprocess": false } ]
8+
]
9+
}

examples/with-styled-components/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
"start": "next start"
88
},
99
"dependencies": {
10+
"babel-plugin-styled-components": "^1.1.4",
11+
"babel-preset-stage-0": "^6.24.1",
1012
"next": "latest",
1113
"react": "^15.4.2",
1214
"react-dom": "^15.4.2",
13-
"styled-components": "^1.4.4"
15+
"styled-components": "^2.0.0-17"
1416
},
1517
"author": "",
1618
"license": "ISC"

examples/with-styled-components/pages/_document.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import Document, { Head, Main, NextScript } from 'next/document'
2-
import styleSheet from 'styled-components/lib/models/StyleSheet'
2+
import { ServerStyleSheet } from 'styled-components'
33

44
export default class MyDocument extends Document {
5-
static async getInitialProps ({ renderPage }) {
6-
const page = renderPage()
7-
const styles = (
8-
<style dangerouslySetInnerHTML={{ __html: styleSheet.rules().map(rule => rule.cssText).join('\n') }} />
9-
)
10-
return { ...page, styles }
11-
}
12-
135
render () {
6+
const sheet = new ServerStyleSheet()
7+
const main = sheet.collectStyles(<Main />)
8+
const styleTags = sheet.getStyleElement()
149
return (
1510
<html>
1611
<Head>
1712
<title>My page</title>
13+
{styleTags}
1814
</Head>
1915
<body>
20-
<Main />
16+
<div className='root'>
17+
{main}
18+
</div>
2119
<NextScript />
2220
</body>
2321
</html>

0 commit comments

Comments
 (0)