@@ -32,6 +32,12 @@ export default function handleRender(req, res) {
3232 // Grab the initial state from our Redux store
3333 const finalState = store . getState ( ) ;
3434
35+ // If SSR is disabled, just render the skeleton HTML.
36+ if ( ! config . enableSSR ) {
37+ const markup = render ( null , finalState , [ ] ) ;
38+ return res . send ( markup ) ;
39+ }
40+
3541 // See react-router's Server Rendering section:
3642 // https://reacttraining.com/react-router/web/guides/server-rendering
3743 const matchRoutes = routes => {
@@ -88,20 +94,30 @@ export default function handleRender(req, res) {
8894
8995 let context = { } , modules = [ ] ;
9096
91- const component = (
92- < Loadable . Capture report = { moduleName => modules . push ( moduleName ) } >
97+ const getComponent = ( ) => {
98+ let component = (
9399 < Provider store = { store } >
94100 < StaticRouter context = { context } location = { req . baseUrl } >
95101 < App />
96102 </ StaticRouter >
97103 </ Provider >
98- </ Loadable . Capture >
99- ) ;
104+ ) ;
105+
106+ if ( config . enableDynamicImports ) {
107+ return (
108+ < Loadable . Capture report = { moduleName => modules . push ( moduleName ) } >
109+ { component }
110+ </ Loadable . Capture >
111+ ) ;
112+ }
113+
114+ return component ;
115+ } ;
100116
101117 // Execute the render only after all promises have been resolved.
102118 Promise . all ( fetchData ) . then ( ( ) => {
103119 const state = store . getState ( ) ;
104- const html = renderToString ( component ) ;
120+ const html = renderToString ( getComponent ( ) ) ;
105121 const bundles = stats && getBundles ( stats , modules ) || [ ] ;
106122 const markup = render ( html , state , bundles ) ;
107123
0 commit comments