-
Notifications
You must be signed in to change notification settings - Fork 47.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fizz/Flight] Don't start writing to the stream if it's already full #22726
Conversation
Comparing: 2b77ab2...8b6d828 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
I don't have context on this and Seb is out for a bit. Is this blocking you? |
ping @sebmarkbage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, this makes sense. The goal is that we'd ideally own the whole stream and at that point it'd be unnecessary to check this. At some point we might want to revert this for that reason. For now it's not practical to let React own the stream.
destination.cork(); | ||
export function beginWriting(destination: Destination): boolean { | ||
// Older versions of Node don't have this. | ||
if (destination.writableNeedDrain !== true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about writableLength >= writableHighWaterMark
? It goes back a little further in terms of Node versions. That's what write()
practically returns, and what is checked before needDrain is set to true. It's also how we implement that for web streams.
Summary
Currently, React will always write something when flushing completed work, because it never checks if the stream is full until after writing. With this change, React will bail out early and continue buffering if we know we're still waiting for the stream to drain, so that we only write the most up-to-date data to the stream.
How did you test this change?
Existing tests pass. Could probably use a test to validate full behavior.