@samitouri / QOS-React-1 / commits / 0d11563b4a

[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.

Sebastian Markbåge committed Feb 6, 2024 at 13:17 UTC 0d11563b4a96e0f4f2361cdf7375b12375688163
1 file changed +1 -4
packages/react-server/src/ReactFlightServer.js
+1 -4
@@ -296,7 +296,6 @@ export function createRequest(
296 onError: onError === undefined ? defaultErrorHandler : onError,
297 onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone,
298 };
299 - request.pendingChunks++;
299 const rootTask = createTask(request, model, null, false, abortSet);
300 pingedTasks.push(rootTask);
301 return request;
@@ -318,7 +317,6 @@ function serializeThenable(
317 task: Task,
318 thenable: Thenable<any>,
319 ): number {
321 - request.pendingChunks++;
320 const newTask = createTask(
321 request,
322 null,
@@ -722,6 +720,7 @@ function createTask(
720 implicitSlot: boolean,
721 abortSet: Set<Task>,
722 ): Task {
723 + request.pendingChunks++;
724 const id = request.nextChunkId++;
725 if (typeof model === 'object' && model !== null) {
726 // 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(
905 }
906
907 function outlineModel(request: Request, value: ReactClientValue): number {
909 - request.pendingChunks++;
908 const newTask = createTask(
909 request,
910 value,
@@ -1068,7 +1066,6 @@ function renderModel(
1066 // $FlowFixMe[method-unbinding]
1067 if (typeof x.then === 'function') {
1068 // Something suspended, we'll need to create a new task and resolve it later.
1071 - request.pendingChunks++;
1069 const newTask = createTask(
1070 request,
1071 task.model,