webkom/lego

Change SSR to render to stream instead of to string.

Opened this issue · 0 comments

Currently, the SSR renders components to a HTML string before it responds with anything.

renderToString() is a fully blocking operation and this can take a while (a few seconds), which has a couple of downsides:

  • Relatively bad perceived performance (compared to CSR and other types of SSR, which emit the "blank loading page")
  • Since the black magic of SEO seems to be somewhat impatient, too slow SSR might lead to a timeout for various web crawlers. ...which is bad for us

renderToNodeStream() is now deprecated, so renderToPipeableStream() seems like the only choice here.

A few pitfalls to look out for / Points to remember:

  • Client needs to re-hydrate with each new chunk that is sent
  • Since all types of rendering are blocking, make sure that Worker Threads are used instead of the Main Thread as much as possible
  • Make sure this doesn't break react-prepare

Helpful links:

(This might be be able to Fix up in our issues with Helmet)