during SSR (some may use window, document…) • Some modules require you to use additional API during SSR (react-router, react-redux) • Only nodejs support react SSR, so we have to separate a SSR server
API usage (react-router StaticRouter, react-redux Provider…) • We have to install client-side modules on server (react-router, react-redux) just for SSR • To avoid event loop blocking, we need to separate a SSR server…
state offline, so server can simply serve the result • When it comes to dynamic data, server can put data it fetched from DB to Redux preloadedState Coren generate Server Response + https://github.com/Canner/coren
to preloadedState? • Data not going to change for long time could be fetched at first (e.g. 2011 NBA Finals scores) Example: https://github.com/Canner/coren-example
& redux, you will need to wrap component with <StaticRouter> & <Provider store={store}> • Coren use @reactRouterRedux decorator Example: https://github.com/Canner/coren-example
what to do during SSR. SSR Process Collect all routes from @route decorator Loop routes setOptions Lifecycle wrapSSR appendToHead appendToBody 1. setOptions: set variables that will be shared among decorators 2. wrapSSR: wrap components outside 3. appendToHead: append elements to <head> 4. appendToBody: append elements to <body>
=> avoid first blank page • server respond HTML with dynamic data • => save API round-trip time • easy integrate with webpack, babel and add assets to header • => save develop time • no more import React, ReactDOM… on server