-
Notifications
You must be signed in to change notification settings - Fork 240
renderToNodeStream the full app without renderToString #564
base: next
Are you sure you want to change the base?
Changes from 3 commits
dfc1917
31514bb
d5eb417
84728ee
a107229
d5a2220
f1436f2
1fc35ea
dfe36e8
18aab26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,7 +45,7 @@ function scriptTag(jsFilePath) { | |
| // COMPONENT | ||
|
|
||
| function ServerHTML(props) { | ||
| const { asyncComponentsState, helmet, nonce, reactAppString } = props; | ||
| const { asyncComponentsState, helmet, nonce, children } = props; | ||
|
|
||
| // Creates an inline script definition that is protected by the nonce. | ||
| const inlineScript = body => ( | ||
|
|
@@ -124,8 +124,9 @@ function ServerHTML(props) { | |
| bodyElements={bodyElements.map((x, idx) => ( | ||
| <KeyedComponent key={idx}>{x}</KeyedComponent> | ||
| ))} | ||
| appBodyString={reactAppString} | ||
| /> | ||
| > | ||
| <div id="app">{children}</div> | ||
| </HTML> | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -137,12 +138,12 @@ ServerHTML.propTypes = { | |
| // eslint-disable-next-line react/forbid-prop-types | ||
| helmet: PropTypes.object, | ||
| nonce: PropTypes.string, | ||
| reactAppString: PropTypes.string, | ||
| children: PropTypes.object, | ||
|
||
| }; | ||
|
|
||
| ServerHTML.defaultProps = { | ||
| asyncComponentsState: undefined, | ||
| helmet: undefined, | ||
| nonce: undefined, | ||
| reactAppString: undefined, | ||
| children: undefined, | ||
|
||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,6 @@ | ||
| import React from 'react'; | ||
| import Helmet from 'react-helmet'; | ||
| import { | ||
| renderToString, | ||
| renderToStaticMarkup, | ||
| renderToNodeStream, | ||
| } from 'react-dom/server'; | ||
| import { renderToStaticMarkup, renderToNodeStream } from 'react-dom/server'; | ||
| import { StaticRouter } from 'react-router-dom'; | ||
| import { | ||
| AsyncComponentProvider, | ||
|
|
@@ -62,19 +58,21 @@ export default function reactApplicationMiddleware(request, response) { | |
| </AsyncComponentProvider> | ||
| ); | ||
|
|
||
| const App = () => app; | ||
|
||
|
|
||
| // Pass our app into the react-async-component helper so that any async | ||
| // components are resolved for the render. | ||
| asyncBootstrapper(app).then(() => { | ||
| const appString = renderToString(app); | ||
|
|
||
| // Generate the html response. | ||
| const html = renderToNodeStream( | ||
| <ServerHTML | ||
| reactAppString={appString} | ||
| // reactAppString={appString} | ||
|
||
| nonce={nonce} | ||
| helmet={Helmet.rewind()} | ||
| asyncComponentsState={asyncComponentsContext.getState()} | ||
| />, | ||
| > | ||
| <App /> | ||
| </ServerHTML>, | ||
| ); | ||
|
|
||
| switch (reactRouterContext.status) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,13 +8,13 @@ import PropTypes from 'prop-types'; | |
| * The is the HTML shell for our React Application. | ||
| */ | ||
| function HTML(props) { | ||
| const { htmlAttributes, headerElements, bodyElements, appBodyString } = props; | ||
| const { htmlAttributes, headerElements, bodyElements, children } = props; | ||
|
|
||
| return ( | ||
| <html {...htmlAttributes}> | ||
| <head>{headerElements}</head> | ||
| <body> | ||
| <div id="app" dangerouslySetInnerHTML={{ __html: appBodyString }} /> | ||
| {children} | ||
|
||
| {bodyElements} | ||
| </body> | ||
| </html> | ||
|
|
@@ -26,14 +26,14 @@ HTML.propTypes = { | |
| htmlAttributes: PropTypes.object, | ||
| headerElements: PropTypes.node, | ||
| bodyElements: PropTypes.node, | ||
| appBodyString: PropTypes.string, | ||
| children: PropTypes.object, | ||
|
||
| }; | ||
|
|
||
| HTML.defaultProps = { | ||
| htmlAttributes: null, | ||
| headerElements: null, | ||
| bodyElements: null, | ||
| appBodyString: '', | ||
| children: undefined, | ||
|
||
| }; | ||
|
|
||
| // EXPORT | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be
{children}only