ENV :
node v7.0.0
webpack ^2.2.1
express ^4.14.1
styled-components@next
with babel-plugin-styled-components
["styled-components", {
"transpileTemplateLiterals": true,
"ssr": true,
"displayName": false,
"minify": true
}]
yarn run v0.16.1
$ NODE_ENV=server node server
Listening http://localhost:5050
.sc-bdVaJa {}
.sc-bdVaJa {}
.sc-bdVaJa {}.jiiHOZ {width: 100px;height: 100px;background-color: red;}
.sc-bdVaJa {}.jiiHOZ {width: 100px;height: 100px;background-color: red;}
What's the code for the components?
simple enough @mxstbr
import React from 'react'
import styled from 'styled-components'
const Box = styled.div`
width: 100px;
height: 100px;
background-color: red;
`
const Home = () => {
return (
<div>
<Box />
</div>
)
}
export default Home
server
require('babel-register')
const express = require('express')
const React = require('react')
const ReactDOMServer = require('react-dom/server')
const ReactRouter = require('react-router-dom')
const App = require('../src/app').default
const path = require('path')
const Helmet = require('react-helmet')
const styleSheet = require('styled-components/lib/models/StyleSheet')
const compression = require('compression')
const _ = require('lodash')
const StaticRouter = ReactRouter.StaticRouter
const server = express()
server.use(compression())
server.use('/static', express.static(path.join(__dirname, '../public/static')))
styleSheet.reset()
server.use((req, res) => {
const context = {}
const body = ReactDOMServer.renderToString(
React.createElement(StaticRouter, {
location: req.url,
context: context
},
React.createElement(App))
)
console.log(
styleSheet.getCSS()
)
const seo = Helmet.rewind()
const html = `
<!doctype html>
<html ${seo.htmlAttributes.toString()}>
<head>
${seo.title.toString()}
${seo.meta.toString()}
${seo.link.toString()}
</head>
<body>
<div id='root'>
<%= body %>
</div>
<script src='/static/js/bundle.app.js'></script>
</body>
</html>
`
const makeTemplate = _.template(html)
if (context.url) {
res.writeHead(302, {
Location: context.url
})
res.end()
} else {
res.write(makeTemplate({body: body}))
res.end()
}
})
const PORT = 5050
server.listen(PORT, () => {
console.log(`Listening http://localhost:5050`)
})
This is a duplicate of #378, thanks for the detailed bug report! Please track that issue.