Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
feat(ssr): render Helmet on server
Browse files Browse the repository at this point in the history
  • Loading branch information
Metnew committed Feb 19, 2018
1 parent 066d6bf commit 3378ff6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/server/ssr/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @desc
*/
import React from 'react'
import Helmet from 'react-helmet'
import {renderToString} from 'react-dom/server'
import {ServerStyleSheet, StyleSheetManager} from 'styled-components'
import {configureRootComponent, configureApp} from 'common/app'
Expand Down Expand Up @@ -33,9 +34,7 @@ export default async (req: express$Request, res: express$Response) => {

const app = (
<AsyncComponentProvider asyncContext={asyncContext}>
<StyleSheetManager sheet={sheet.instance}>
{RootComponent}
</StyleSheetManager>
<StyleSheetManager sheet={sheet.instance}>{RootComponent}</StyleSheetManager>
</AsyncComponentProvider>
)

Expand All @@ -45,6 +44,7 @@ export default async (req: express$Request, res: express$Response) => {

asyncBootstrapper(app).then(() => {
const renderedApp = renderToString(app)
const helmet = Helmet.renderStatic()
const css: string = sheet.getStyleTags()
const preloadedState: Object = store.getState()
const responseStatusCode = noRequestURLMatch ? 404 : 200
Expand All @@ -55,7 +55,8 @@ export default async (req: express$Request, res: express$Response) => {
asyncState,
initialState: preloadedState,
app: renderedApp,
i18n
i18n,
helmet
}

res.status(responseStatusCode).send(HTMLComponent(props))
Expand Down

0 comments on commit 3378ff6

Please sign in to comment.