DEV Community

Artur Slomowski
Artur Slomowski

Posted on

RenderToNodeStream and http status codes

Hi,

I would like to implement streaming rendering to our app.
However, as far I know it is not possible to change http status code during rendering and streaming.

It means if I start streaming, it sends 200 to the browser, and even if during rendering something will happen, we cannot change status to 500 or 404.

How are people dealing with this in the case of streaming rendering?
Streaming rendering is highly recommended by the google team for improving core web vitals, but on the other hand, it's not SEO friendly at all.

Here is example code:

res.write(htmlHeader);

const renderingStream = renderToNodeStream(<App />);

renderingStream.pipe(res);

renderingStream.on('end', () => {
 res.end();
});

// I am tracking error a bit differently, it is just example
renderingStream.on('error', () => {
  res.status(500);
});
Enter fullscreen mode Exit fullscreen mode

Top comments (0)