Skip to content

Commit

Permalink
[Flight] Move pendingChunks ref count increment into createTask (#28260)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage authored Feb 6, 2024
1 parent 6692445 commit 0d11563
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -318,7 +317,6 @@ function serializeThenable(
task: Task,
thenable: Thenable<any>,
): number {
request.pendingChunks++;
const newTask = createTask(
request,
null,
Expand Down Expand Up @@ -722,6 +720,7 @@ function createTask(
implicitSlot: boolean,
abortSet: Set<Task>,
): 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
Expand Down Expand Up @@ -906,7 +905,6 @@ function serializeClientReference(
}

function outlineModel(request: Request, value: ReactClientValue): number {
request.pendingChunks++;
const newTask = createTask(
request,
value,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 0d11563

Please sign in to comment.