Skip to content

Commit 3aacb60

Browse files
committed
switch flowing
1 parent 3852aef commit 3aacb60

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function renderToReadableStream(
2626
options?: Options,
2727
): ReadableStream {
2828
let request;
29-
return new ReadableStream({
29+
const stream = new ReadableStream({
3030
start(controller) {
3131
request = createRequest(
3232
model,
@@ -37,10 +37,17 @@ function renderToReadableStream(
3737
startWork(request);
3838
},
3939
pull(controller) {
40-
startFlowing(request);
40+
// Pull is called immediately even if the stream is not passed to anything.
41+
// That's buffering too early. We want to start buffering once the stream
42+
// is actually used by something so we can give it the best result possible
43+
// at that point.
44+
if (stream.locked) {
45+
startFlowing(request);
46+
}
4147
},
4248
cancel(reason) {},
4349
});
50+
return stream;
4451
}
4552

4653
export {renderToReadableStream};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ function pipeToNodeWritable(
3737
webpackMap,
3838
options ? options.onError : undefined,
3939
);
40-
destination.on('drain', createDrainHandler(destination, request));
4140
startWork(request);
41+
startFlowing(request);
42+
destination.on('drain', createDrainHandler(destination, request));
4243
}
4344

4445
export {pipeToNodeWritable};

0 commit comments

Comments
 (0)