Skip to content

Commit 2133306

Browse files
committed
1.0.7
1.0.7 - 2017-04-17 ------------------------------------------------ * Optimises `window.*` initial variables on SSR by removing whitespace * Allows passing a `window` prop to `<Html>` on SSR, instead of separate props for `webpackManifest` / `state`
1 parent 02b4536 commit 2133306

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.0.7 - 2017-04-17
2+
------------------------------------------------
3+
* Optimises `window.*` initial variables on SSR by removing whitespace
4+
* Allows passing a `window` prop to `<Html>` on SSR, instead of separate props for `webpackManifest` / `state`
5+
16
1.0.6 - 2017-04-17
27
------------------------------------------------
38
* Moves `manifest.json` and `chunk-manifest.json` to `dist` instead of `dist/public` (stops them being accessible publicly)

kit/entry/server.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ const PORT = process.env.PORT || 4000;
146146
<Html
147147
html={html}
148148
head={Helmet.rewind()}
149-
state={store.getState()}
149+
window={{
150+
webpackManifest: chunkManifest,
151+
__STATE__: store.getState(),
152+
}}
150153
scripts={scripts}
151-
chunkManifest={chunkManifest}
152154
css={manifest['browser.css']} />,
153155
)}`;
154156
});

kit/views/ssr.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable react/no-danger */
1+
/* eslint-disable react/no-danger, no-return-assign, no-param-reassign */
22

33
// Component to render the full HTML response in React
44

@@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
99

1010
// ----------------------
1111

12-
const Html = ({ head, html, state, scripts, chunkManifest, css }) => (
12+
const Html = ({ head, html, scripts, window, css }) => (
1313
<html lang="en" prefix="og: http://ogp.me/ns#">
1414
<head>
1515
<meta charSet="utf-8" />
@@ -19,18 +19,16 @@ const Html = ({ head, html, state, scripts, chunkManifest, css }) => (
1919
{head.meta.toComponent()}
2020
<link rel="stylesheet" href={css} />
2121
{head.title.toComponent()}
22-
<script
23-
dangerouslySetInnerHTML={{
24-
__html: `window.webpackManifest = ${JSON.stringify(chunkManifest)}`,
25-
}} />
2622
</head>
2723
<body>
2824
<div
2925
id="main"
3026
dangerouslySetInnerHTML={{ __html: html }} />
3127
<script
3228
dangerouslySetInnerHTML={{
33-
__html: `window.__STATE__ = ${JSON.stringify(state)}`,
29+
__html: Object.keys(window).reduce(
30+
(out, key) => out += `window.${key}=${JSON.stringify(window[key])};`,
31+
''),
3432
}} />
3533
{scripts.map(src => <script key={src} defer src={src} />)}
3634
</body>
@@ -40,9 +38,8 @@ const Html = ({ head, html, state, scripts, chunkManifest, css }) => (
4038
Html.propTypes = {
4139
head: PropTypes.object.isRequired,
4240
html: PropTypes.string.isRequired,
43-
state: PropTypes.object.isRequired,
41+
window: PropTypes.object.isRequired,
4442
scripts: PropTypes.arrayOf(PropTypes.string).isRequired,
45-
chunkManifest: PropTypes.object.isRequired,
4643
css: PropTypes.string.isRequired,
4744
};
4845

0 commit comments

Comments
 (0)