Closed murshex closed 6 years ago
This project is framework agnostic, so it doesn't know (and assume) anything about your site's content. Even if this loader was oriented towards React users, using the renderToNodeStream
function wouldn't solve anything as this loader and JSDOM would have to wait for the entire stream to be generated (streams are useful for directly piping React's output to a HTTP socket).
Correct - since this is prerendering, the output is a static content so there's no value in streaming VS buffered rendering.
FWIW your prerender can return a Promise, so you could invoke pipe the result of renderToNodeStream()
into a Buffer and wrap that in a promise. I can never remember these APIs without looking, but it'd be something like:
import getStream from 'get-stream' // see https://npm.im/get-stream
export default function() {
const stream = renderToNodeStream(<App />)
// collect the streamed HTML up into a string and return a promise that resolves when done:
return getStream(stream)
}
This is all likely a bit slower than just using renderToString(), since there is very little difference between that and the stream renderer. Both render synchronous, the streaming renderer just serializes lazily.
Is it possible to use "renderToNodeStream" to increase the build time?