Skip to content

Commit

Permalink
Explicitly set highWaterMark to 0 for ReadableStream (#24641)
Browse files Browse the repository at this point in the history
* Explicitly set highWaterMark to 0 for ReadableStreams

This is because not all streaming implementations respect the
default behavior of settings highWaterMark to 0 for byte streams.
Being explicit guarantees the intended behavior across runtimes.

* Remove size methods and add FlowFixMe instead
  • Loading branch information
jplhomer committed May 31, 2022
1 parent 25837ac commit 26a5b3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
20 changes: 12 additions & 8 deletions packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
Expand Up @@ -53,15 +53,19 @@ function renderToReadableStream(
});

function onShellReady() {
const stream: ReactDOMServerReadableStream = (new ReadableStream({
type: 'bytes',
pull(controller) {
startFlowing(request, controller);
const stream: ReactDOMServerReadableStream = (new ReadableStream(
{
type: 'bytes',
pull(controller) {
startFlowing(request, controller);
},
cancel(reason) {
abort(request);
},
},
cancel(reason) {
abort(request);
},
}): any);
// $FlowFixMe size() methods are not allowed on byte streams.
{highWaterMark: 0},
): any);
// TODO: Move to sub-classing ReadableStream.
stream.allReady = allReady;
resolve(stream);
Expand Down
Expand Up @@ -33,16 +33,20 @@ function renderToReadableStream(
options ? options.onError : undefined,
context,
);
const stream = new ReadableStream({
type: 'bytes',
start(controller) {
startWork(request);
const stream = new ReadableStream(
{
type: 'bytes',
start(controller) {
startWork(request);
},
pull(controller) {
startFlowing(request, controller);
},
cancel(reason) {},
},
pull(controller) {
startFlowing(request, controller);
},
cancel(reason) {},
});
// $FlowFixMe size() methods are not allowed on byte streams.
{highWaterMark: 0},
);
return stream;
}

Expand Down

0 comments on commit 26a5b3c

Please sign in to comment.