13 ms·
That sounds really cool! How simple/difficult was it to set up the prerendering and what kind of stack are you running?
by rajangdavis 11y ago
That sounds really cool! How simple/difficult was it to set up the prerendering and what kind of stack are you running?
- k__ 11y agoThe only ugly part was getting the client side React to pick up the server side markup when it comes "pre-filled" with dynamic data. The client needs to use the same data or else it will throw away the whole markup and re-render it. Fetch the data on the server before you render. Render the (static) markup with React and the data. Send the markup AND the (serialized) data to the client. The client will render the markup normally before React kicks in. The client React then needs a way to use the serialized data with the pre-rendered markup. Redux, for example, is a way to pass down this data to every component, so it's available at render. Normally, when writing React apps, you can simply load data async and show a place-holder while the request runs. If you want to render on server, all the data has to be fetched before, if it's loaded async, so the server can render synchronously.