From 0d11563b4a96e0f4f2361cdf7375b12375688163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?= Date: Tue, 6 Feb 2024 13:17:59 -0800 Subject: [PATCH] [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. --- packages/react-server/src/ReactFlightServer.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/react-server/src/ReactFlightServer.js b/packages/react-server/src/ReactFlightServer.js index b0e37e20b507c..d0711e414e5c9 100644 --- a/packages/react-server/src/ReactFlightServer.js +++ b/packages/react-server/src/ReactFlightServer.js @@ -296,7 +296,6 @@ export function createRequest( onError: onError === undefined ? defaultErrorHandler : onError, onPostpone: onPostpone === undefined ? defaultPostponeHandler : onPostpone, }; - request.pendingChunks++; const rootTask = createTask(request, model, null, false, abortSet); pingedTasks.push(rootTask); return request; @@ -318,7 +317,6 @@ function serializeThenable( task: Task, thenable: Thenable, ): number { - request.pendingChunks++; const newTask = createTask( request, null, @@ -722,6 +720,7 @@ function createTask( implicitSlot: boolean, abortSet: Set, ): Task { + request.pendingChunks++; const id = request.nextChunkId++; if (typeof model === 'object' && model !== null) { // 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( } function outlineModel(request: Request, value: ReactClientValue): number { - request.pendingChunks++; const newTask = createTask( request, value, @@ -1068,7 +1066,6 @@ function renderModel( // $FlowFixMe[method-unbinding] if (typeof x.then === 'function') { // Something suspended, we'll need to create a new task and resolve it later. - request.pendingChunks++; const newTask = createTask( request, task.model,