-
Notifications
You must be signed in to change notification settings - Fork 242
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be |
||
}; | ||
|
||
ServerHTML.defaultProps = { | ||
asyncComponentsState: undefined, | ||
helmet: undefined, | ||
nonce: undefined, | ||
reactAppString: undefined, | ||
children: undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. React expect |
||
}; |
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. place this below asyncBootstrapper, because async bootstrapper run all function to preloaded data in with |
||
|
||
// 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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should preserve this code as comment |
||
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} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should remain with this |
||
{bodyElements} | ||
</body> | ||
</html> | ||
|
@@ -26,14 +26,14 @@ HTML.propTypes = { | |
htmlAttributes: PropTypes.object, | ||
headerElements: PropTypes.node, | ||
bodyElements: PropTypes.node, | ||
appBodyString: PropTypes.string, | ||
children: PropTypes.object, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
}; | ||
|
||
HTML.defaultProps = { | ||
htmlAttributes: null, | ||
headerElements: null, | ||
bodyElements: null, | ||
appBodyString: '', | ||
children: undefined, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be |
||
}; | ||
|
||
// 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