git ssb

1+

dinoworm ๐Ÿ› / catstack



Commit 3582ba8ad59f6e36f60142e530d0794c1e02c095

proper server-side render (passes the checksum)

- was failing because we were rendering differently on the client for dev-tools, so now do initial render same as server and if in dev then render again with dev tools
Michael Williams committed on 11/29/2015, 4:29:25 AM
Parent: d257f1cb78aa333ab6399429df9d754ce4f561f5

Files changed

app/client.jschanged
app/stack/render.jschanged
app/client.jsView
@@ -9,30 +9,37 @@
99 const createStore = require('app/store')
1010 const fetchElement = require('app/util/fetch-element')
1111
1212 if (process.env.NODE_ENV === 'development') {
13- var DevTools = require('app/components/dev-tools')
1413 }
1514
1615 const store = createStore(window.__data)
1716 const history = createHistory()
1817
1918 syncReduxAndRouter(history, store)
2019
21-const component = (
20+const main = (
2221 <Router createElement={fetchElement} history={history}>
2322 { routes }
2423 </Router>
2524 )
2625
2726 render(
2827 <Provider store={store} key="provider">
29- <div>
30- { component }
31- {
32- (process.env.NODE_ENV === 'development') ?
33- <DevTools /> : null
34- }
35- </div>
28+ { main }
3629 </Provider>,
3730 document.querySelector('main')
3831 )
32+
33+if (process.env.NODE_ENV === 'development') {
34+ const DevTools = require('app/components/dev-tools')
35+
36+ render(
37+ <Provider store={store} key="provider">
38+ <div>
39+ { main }
40+ <DevTools />
41+ </div>
42+ </Provider>,
43+ document.querySelector('main')
44+ )
45+}
app/stack/render.jsView
@@ -36,20 +36,20 @@
3636 const component = <Provider store={store} key="provider">
3737 <RoutingContext { ...renderProps } />
3838 </Provider>
3939
40- const html = renderToString(component)
40+ const innerHtml = renderToString(component)
4141
42- const fullHtml = renderFullPage(html, store.getState())
42+ const html = renderFullPage(innerHtml, store.getState())
4343
44- res.send(fullHtml)
44+ res.send(html)
4545 })
4646 }
4747 })
4848 }
4949 }
5050
51-function renderFullPage (html, data) {
51+function renderFullPage (innerHtml, initialData) {
5252 return `
5353 <!DOCTYPE html>
5454 <html lang="en">
5555 <head>
@@ -57,11 +57,11 @@
5757 <title>Production TodoMVC</title>
5858 <meta name="viewport" content="width=device-width, initial-scale=1" />
5959 </head>
6060 <body>
61- <main>${ html }</main>
61+ <main>${ innerHtml }</main>
6262 <script>
63- window.__data = ${ JSON.stringify(data) }
63+ window.__data = ${ JSON.stringify(initialData) }
6464 </script>
6565 <script src="bundle.js"></script>
6666 </body>
6767 </html>

Built with git-ssb-web