@@ -60,20 +60,16 @@ app.get("*", (req, res) => {
6060 res . redirect ( 302 , redirectLocation . pathname + redirectLocation . search ) ;
6161 } else if ( renderProps ) {
6262 store . runSaga ( rootSaga ) . done . then ( ( ) => {
63- // store will be mutated during the second render (because of componentDidMount)
64- // deep clone state
63+ // deep clone state because store will be mutated during the second render in componentWillMount
6564 const initialState = JSON . parse ( JSON . stringify ( store . getState ( ) ) ) ;
66- console . info ( "before markup => store.stars = " + JSON . stringify ( store . getState ( ) . stars ) ) ;
65+
66+ // render again from the initial data
6767 const markup = renderToString (
6868 < Provider store = { store } key = "provider" >
6969 < RouterContext { ...renderProps } />
7070 </ Provider >
7171 ) ;
72- console . info ( "after markup => store.stars = " + JSON . stringify ( store . getState ( ) . stars ) ) ;
73- console . info ( "--------------------------------" ) ;
74- console . info ( "--------------------------------" ) ;
75- console . info ( "--------------------------------" ) ;
76- console . info ( "markup = " + markup ) ;
72+
7773 if ( appConfig . ssr ) {
7874 res . status ( 200 ) . send ( renderHTML ( markup , initialState ) ) ;
7975 } else {
@@ -88,12 +84,13 @@ app.get("*", (req, res) => {
8884 res . status ( 500 ) . send ( err . message ) ;
8985 } ) ;
9086
91- console . info ( "before renderToString => state.stars = " + JSON . stringify ( store . getState ( ) . stars ) ) ;
87+ // first render to activate componentWillMount to dispatch actions for loading initial data
9288 renderToString (
9389 < Provider store = { store } key = "provider" >
9490 < RouterContext { ...renderProps } />
9591 </ Provider >
9692 ) ;
93+ // dispatching END will cause the root saga to terminate after all fired tasks terminate
9794 store . close ( ) ;
9895 } else {
9996 res . status ( 404 ) . send ( "Not Found?" ) ;
0 commit comments