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

Commit

Permalink
feat(server/ssr): React 16 streaming, remove rapscallion
Browse files Browse the repository at this point in the history
feat(server/ssr): React 16 streaming, remove rapscallion
  • Loading branch information
Metnew committed Sep 28, 2017
1 parent ed419d1 commit 1b76528
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/server/ssr/HtmlComponent.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
// @flow
import serealize from 'serialize-javascript'
import {template} from 'rapscallion'
type args = {
css: string,
App: string,
initialState: Object,
assets: Object,
faviconsAssets: Object,
Expand All @@ -20,7 +18,6 @@ const DLLScripts =

const HtmlComponent = ({
css,
App,
initialState,
assets,
faviconsAssets,
Expand All @@ -34,10 +31,11 @@ const HtmlComponent = ({
js: ({path}) => `<script src="${path}" type="text/javascript"></script>`
}
const getTags = assets => funcs => ext => {
// sort assets to be injected in right order
const assetsOrdered = ['manifest', 'vendor', 'client']
return Object.keys(assets)
.filter(bundleName => assets[bundleName][ext])
.sort((a, b) => assetsOrdered.indexOf(a) > assetsOrdered.indexOf(b))
.sort((a, b) => assetsOrdered.indexOf(a) - assetsOrdered.indexOf(b))
.map(bundleName => {
const path = assets[bundleName][ext]
return funcs[ext]({path})
Expand All @@ -48,8 +46,8 @@ const HtmlComponent = ({
const cssTags = getTagsFromAssets('css')
const jsTags = getTagsFromAssets('js')

return template`
<html lang="${i18n.lang}">
return {
beforeAppTag: `<html lang="${i18n.lang}">
<head>
<meta charset="utf-8" />
<title>Noir</title>
Expand All @@ -66,18 +64,19 @@ const HtmlComponent = ({
${css}
${cssTags}
<head>
<body>
<div id="app">${App}</div>
<script>window.__INITIAL_STATE__ = ${safeStringifiedState}</script>
<script>window.__I18N__ = ${stringifiedI18N}</script>
${DLLScripts}
${jsTags}
<noscript>
You are using outdated browser. You can install modern browser here:
<a href="http://outdatedbrowser.com/">http://outdatedbrowser.com</a>.
</noscript>
<body>`,
afterAppTag: `
<script>window.__INITIAL_STATE__ = ${safeStringifiedState}</script>
<script>window.__I18N__ = ${stringifiedI18N}</script>
${DLLScripts}
${jsTags}
<noscript>
You are using outdated browser. You can install modern browser here:
<a href="http://outdatedbrowser.com/">http://outdatedbrowser.com</a>.
</noscript>
</body>
</html>`
</html>`
}
}

export default HtmlComponent

0 comments on commit 1b76528

Please sign in to comment.