Skip to content

Commit 0d11563

Browse files
authored
[Flight] Move pendingChunks ref count increment into createTask (#28260)
Every time we create a task we need to wait for it so we increase a ref count. We can do this in `createTask`. This is in line with what Fizz does too. They differ in that Flight counts when they're actually flushed where as Fizz decrements them when they complete. Flight should probably count them when they complete so it's possible to wait for the end before flushing for buffering purposes.
1 parent 6692445 commit 0d11563

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

packages/react-server/src/ReactFlightServer.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ export function createRequest(
296296
onError: onError === undefined ? defaultErrorHandler : onError,
297297
onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone,
298298
};
299-
request.pendingChunks++;
300299
const rootTask = createTask(request, model, null, false, abortSet);
301300
pingedTasks.push(rootTask);
302301
return request;
@@ -318,7 +317,6 @@ function serializeThenable(
318317
task: Task,
319318
thenable: Thenable<any>,
320319
): number {
321-
request.pendingChunks++;
322320
const newTask = createTask(
323321
request,
324322
null,
@@ -722,6 +720,7 @@ function createTask(
722720
implicitSlot: boolean,
723721
abortSet: Set<Task>,
724722
): Task {
723+
request.pendingChunks++;
725724
const id = request.nextChunkId++;
726725
if (typeof model === 'object' && model !== null) {
727726
// If we're about to write this into a new task we can assign it an ID early so that
@@ -906,7 +905,6 @@ function serializeClientReference(
906905
}
907906

908907
function outlineModel(request: Request, value: ReactClientValue): number {
909-
request.pendingChunks++;
910908
const newTask = createTask(
911909
request,
912910
value,
@@ -1068,7 +1066,6 @@ function renderModel(
10681066
// $FlowFixMe[method-unbinding]
10691067
if (typeof x.then === 'function') {
10701068
// Something suspended, we'll need to create a new task and resolve it later.
1071-
request.pendingChunks++;
10721069
const newTask = createTask(
10731070
request,
10741071
task.model,

0 commit comments

Comments
 (0)