Post

A new React 19 feature that might have gone unnoticed: ReactDOMStatic.prerender(<App />) It's like the old renderToString API, but unlike renderToString, prerender will wait for Suspense boundaries to finish before returning the HTML.

Possibly silly question: what's the difference between this vs onAllReady via the standard react streaming APIs? I'm assuming the latter is still the recommended way to fully buffer pages for bots, for example? Curious if there are limitations in one or the other I'm overlooking

0 reposts1 like

The former with onAllReady will emit all the intermediate suspense fallbacks plus the content, this will just contain the html with content, so it’s more optimized for this use case.

Ah, thanks - that's interesting since the bot usecase in my mind seems like it's actually closer to wanting just the html (since presumably intermediate fallbacks require js to patch up?), which would seem to favour prerender over onAllReady This is assuming we want zero-js-required first paint

Maybe "require js to patch up" isn't quite right since I'd imagine they end up as hidden elements in the DOM anyway, so bots wouldn't care. I want to spend some more time with these APIs - this one seems very handy!

Yeah the bot use case is a probably a good one for using the stream instead of rendering to a string and then responding, but I’m not an expert there