React 18 and headers changing during streaming
artem-malko opened this issue · comments
Hi! My question is about React 18 and SSR with pipeToNodeWritable.
We have a great demo from @gaearon https://codesandbox.io/s/9hfqt with all new features with SSR. So, let's imagine, I want to set up cookie on the server side. In our example we need to have an isomorphic cookie implementation. On the client side we will use document.cookie and on the server side we will write our cookie to the specific header.
And there is a problem. Let's try to write a cookie to the response object from express somewhere in a render, in any component. I know, looks like a bad idea, but it's just for an example.
So, If we will use pipeToNodeWritable, we will have an error, that we can not change Headers, cause they are already sent. Actually it looks like a problem with a correct HTTP-code, if something errored before we started streaming. But what should I do, if I need to change the response during streaming?
May be you have some ideas, how to fix this? Of course I know, I can use onCompleteAll
instead of onReadyToStream
, but I'll miss all new features like selective rehydration in that case.
But what should I do, if I need to change the response during streaming
Well, you can't do that. When you are streaming, headers are already sent
Ok(