@samitouri / QOS-React-2 / commits / 26a5b3c7f7

Explicitly set `highWaterMark` to 0 for `ReadableStream` (#24641)

* 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

Josh Larson committed May 31, 2022 at 15:20 UTC 26a5b3c7f781e93b5bcf4e5a7a6f13233409475d
2 files changed +25 -17
packages/react-dom/src/server/ReactDOMFizzServerBrowser.js
+12 -8
@@ -53,15 +53,19 @@ function renderToReadableStream(
53 });
54
55 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 + },
65 },
61 - cancel(reason) {
62 - abort(request);
63 - },
64 - }): any);
66 + // $FlowFixMe size() methods are not allowed on byte streams.
67 + {highWaterMark: 0},
68 + ): any);
69 // TODO: Move to sub-classing ReadableStream.
70 stream.allReady = allReady;
71 resolve(stream);
packages/react-server-dom-webpack/src/ReactFlightDOMServerBrowser.js
+13 -9
@@ -33,16 +33,20 @@ function renderToReadableStream(
33 options ? options.onError : undefined,
34 context,
35 );
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) {},
46 },
41 - pull(controller) {
42 - startFlowing(request, controller);
43 - },
44 - cancel(reason) {},
45 - });
47 + // $FlowFixMe size() methods are not allowed on byte streams.
48 + {highWaterMark: 0},
49 + );
50 return stream;
51 }
52