Skip to content

Commit 2024c88

Browse files
committed
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.
1 parent 1328ff7 commit 2024c88

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

packages/react-dom/src/server/ReactDOMFizzServerBrowser.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,21 @@ function renderToReadableStream(
5353
});
5454

5555
function onShellReady() {
56-
const stream: ReactDOMServerReadableStream = (new ReadableStream({
57-
type: 'bytes',
58-
pull(controller) {
59-
startFlowing(request, controller);
56+
const stream: ReactDOMServerReadableStream = (new ReadableStream(
57+
{
58+
type: 'bytes',
59+
pull(controller) {
60+
startFlowing(request, controller);
61+
},
62+
cancel(reason) {
63+
abort(request);
64+
},
6065
},
61-
cancel(reason) {
62-
abort(request);
66+
{
67+
highWaterMark: 0,
68+
size: () => 1,
6369
},
64-
}): any);
70+
): any);
6571
// TODO: Move to sub-classing ReadableStream.
6672
stream.allReady = allReady;
6773
resolve(stream);

packages/react-server-dom-webpack/src/ReactFlightDOMServerBrowser.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,22 @@ function renderToReadableStream(
3333
options ? options.onError : undefined,
3434
context,
3535
);
36-
const stream = new ReadableStream({
37-
type: 'bytes',
38-
start(controller) {
39-
startWork(request);
36+
const stream = new ReadableStream(
37+
{
38+
type: 'bytes',
39+
start(controller) {
40+
startWork(request);
41+
},
42+
pull(controller) {
43+
startFlowing(request, controller);
44+
},
45+
cancel(reason) {},
4046
},
41-
pull(controller) {
42-
startFlowing(request, controller);
47+
{
48+
highWaterMark: 0,
49+
size: () => 1,
4350
},
44-
cancel(reason) {},
45-
});
51+
);
4652
return stream;
4753
}
4854

0 commit comments

Comments
 (0)