@samitouri / QOS-React-1 / commits / 6d2a97a711

[Fizz] Gate legacyContext field on disableLegacyContext (#30173)

We're running out of fields and this one we can avoid at runtime in any modern builds.

Sebastian Markbåge committed Jul 1, 2024 at 15:30 UTC 6d2a97a7113dfac2ad45067001b7e49a98718324
1 file changed +36 -22
packages/react-server/src/ReactFizzServer.js
+36 -22
@@ -243,12 +243,12 @@ type RenderTask = {
243 abortSet: Set<Task>, // the abortable set that this task belongs to
244 keyPath: Root | KeyNode, // the path of all parent keys currently rendering
245 formatContext: FormatContext, // the format's specific context (e.g. HTML/SVG/MathML)
246 - legacyContext: LegacyContext, // the current legacy context that this task is executing in
246 context: ContextSnapshot, // the current new context that this task is executing in
247 treeContext: TreeContext, // the current tree context that this task is executing in
248 componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
249 thenableState: null | ThenableState,
250 isFallback: boolean, // whether this task is rendering inside a fallback tree
251 + legacyContext: LegacyContext, // the current legacy context that this task is executing in
252 // DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
253 // Consider splitting into multiple objects or consolidating some fields.
254 };
@@ -272,12 +272,12 @@ type ReplayTask = {
272 abortSet: Set<Task>, // the abortable set that this task belongs to
273 keyPath: Root | KeyNode, // the path of all parent keys currently rendering
274 formatContext: FormatContext, // the format's specific context (e.g. HTML/SVG/MathML)
275 - legacyContext: LegacyContext, // the current legacy context that this task is executing in
275 context: ContextSnapshot, // the current new context that this task is executing in
276 treeContext: TreeContext, // the current tree context that this task is executing in
277 componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
278 thenableState: null | ThenableState,
279 isFallback: boolean, // whether this task is rendering inside a fallback tree
280 + legacyContext: LegacyContext, // the current legacy context that this task is executing in
281 // DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
282 // Consider splitting into multiple objects or consolidating some fields.
283 };
@@ -462,11 +462,11 @@ function RequestInstance(
462 abortSet,
463 null,
464 rootFormatContext,
465 - emptyContextObject,
465 rootContextSnapshot,
466 emptyTreeContext,
467 null,
468 false,
469 + emptyContextObject,
470 );
471 pingedTasks.push(rootTask);
472 }
@@ -604,11 +604,11 @@ export function resumeRequest(
604 abortSet,
605 null,
606 postponedState.rootFormatContext,
607 - emptyContextObject,
607 rootContextSnapshot,
608 emptyTreeContext,
609 null,
610 false,
611 + emptyContextObject,
612 );
613 pingedTasks.push(rootTask);
614 return request;
@@ -630,11 +630,11 @@ export function resumeRequest(
630 abortSet,
631 null,
632 postponedState.rootFormatContext,
633 - emptyContextObject,
633 rootContextSnapshot,
634 emptyTreeContext,
635 null,
636 false,
637 + emptyContextObject,
638 );
639 pingedTasks.push(rootTask);
640 return request;
@@ -698,11 +698,11 @@ function createRenderTask(
698 abortSet: Set<Task>,
699 keyPath: Root | KeyNode,
700 formatContext: FormatContext,
701 - legacyContext: LegacyContext,
701 context: ContextSnapshot,
702 treeContext: TreeContext,
703 componentStack: null | ComponentStackNode,
704 isFallback: boolean,
705 + legacyContext: LegacyContext,
706 ): RenderTask {
707 request.allPendingTasks++;
708 if (blockedBoundary === null) {
@@ -710,7 +710,7 @@ function createRenderTask(
710 } else {
711 blockedBoundary.pendingTasks++;
712 }
713 - const task: RenderTask = {
713 + const task: RenderTask = ({
714 replay: null,
715 node,
716 childIndex,
@@ -721,13 +721,15 @@ function createRenderTask(
721 abortSet,
722 keyPath,
723 formatContext,
724 - legacyContext,
724 context,
725 treeContext,
726 componentStack,
727 thenableState,
728 isFallback,
730 - };
729 + }: any);
730 + if (!disableLegacyContext) {
731 + task.legacyContext = legacyContext;
732 + }
733 abortSet.add(task);
734 return task;
735 }
@@ -743,11 +745,11 @@ function createReplayTask(
745 abortSet: Set<Task>,
746 keyPath: Root | KeyNode,
747 formatContext: FormatContext,
746 - legacyContext: LegacyContext,
748 context: ContextSnapshot,
749 treeContext: TreeContext,
750 componentStack: null | ComponentStackNode,
751 isFallback: boolean,
752 + legacyContext: LegacyContext,
753 ): ReplayTask {
754 request.allPendingTasks++;
755 if (blockedBoundary === null) {
@@ -756,7 +758,7 @@ function createReplayTask(
758 blockedBoundary.pendingTasks++;
759 }
760 replay.pendingTasks++;
759 - const task: ReplayTask = {
761 + const task: ReplayTask = ({
762 replay,
763 node,
764 childIndex,
@@ -767,13 +769,15 @@ function createReplayTask(
769 abortSet,
770 keyPath,
771 formatContext,
770 - legacyContext,
772 context,
773 treeContext,
774 componentStack,
775 thenableState,
776 isFallback,
776 - };
777 + }: any);
778 + if (!disableLegacyContext) {
779 + task.legacyContext = legacyContext;
780 + }
781 abortSet.add(task);
782 return task;
783 }
@@ -1188,13 +1192,13 @@ function renderSuspenseBoundary(
1192 fallbackAbortSet,
1193 fallbackKeyPath,
1194 task.formatContext,
1191 - task.legacyContext,
1195 task.context,
1196 task.treeContext,
1197 // This stack should be the Suspense boundary stack because while the fallback is actually a child segment
1198 // of the parent boundary from a component standpoint the fallback is a child of the Suspense boundary itself
1199 suspenseComponentStack,
1200 true,
1201 + !disableLegacyContext ? task.legacyContext : emptyContextObject,
1202 );
1203 // TODO: This should be queued at a separate lower priority queue so that we only work
1204 // on preparing fallbacks if we don't have any more main content to task on.
@@ -1328,13 +1332,13 @@ function replaySuspenseBoundary(
1332 fallbackAbortSet,
1333 fallbackKeyPath,
1334 task.formatContext,
1331 - task.legacyContext,
1335 task.context,
1336 task.treeContext,
1337 // This stack should be the Suspense boundary stack because while the fallback is actually a child segment
1338 // of the parent boundary from a component standpoint the fallback is a child of the Suspense boundary itself
1339 suspenseComponentStack,
1340 true,
1341 + !disableLegacyContext ? task.legacyContext : emptyContextObject,
1342 );
1343 // TODO: This should be queued at a separate lower priority queue so that we only work
1344 // on preparing fallbacks if we don't have any more main content to task on.
@@ -3271,13 +3275,13 @@ function spawnNewSuspendedReplayTask(
3275 task.abortSet,
3276 task.keyPath,
3277 task.formatContext,
3274 - task.legacyContext,
3278 task.context,
3279 task.treeContext,
3280 // We pop one task off the stack because the node that suspended will be tried again,
3281 // which will add it back onto the stack.
3282 task.componentStack !== null ? task.componentStack.parent : null,
3283 task.isFallback,
3284 + !disableLegacyContext ? task.legacyContext : emptyContextObject,
3285 );
3286
3287 const ping = newTask.ping;
@@ -3317,13 +3321,13 @@ function spawnNewSuspendedRenderTask(
3321 task.abortSet,
3322 task.keyPath,
3323 task.formatContext,
3320 - task.legacyContext,
3324 task.context,
3325 task.treeContext,
3326 // We pop one task off the stack because the node that suspended will be tried again,
3327 // which will add it back onto the stack.
3328 task.componentStack !== null ? task.componentStack.parent : null,
3329 task.isFallback,
3330 + !disableLegacyContext ? task.legacyContext : emptyContextObject,
3331 );
3332
3333 const ping = newTask.ping;
@@ -3341,7 +3345,9 @@ function renderNode(
3345 // Snapshot the current context in case something throws to interrupt the
3346 // process.
3347 const previousFormatContext = task.formatContext;
3344 - const previousLegacyContext = task.legacyContext;
3348 + const previousLegacyContext = !disableLegacyContext
3349 + ? task.legacyContext
3350 + : emptyContextObject;
3351 const previousContext = task.context;
3352 const previousKeyPath = task.keyPath;
3353 const previousTreeContext = task.treeContext;
@@ -3383,7 +3389,9 @@ function renderNode(
3389 // Restore the context. We assume that this will be restored by the inner
3390 // functions in case nothing throws so we don't use "finally" here.
3391 task.formatContext = previousFormatContext;
3386 - task.legacyContext = previousLegacyContext;
3392 + if (!disableLegacyContext) {
3393 + task.legacyContext = previousLegacyContext;
3394 + }
3395 task.context = previousContext;
3396 task.keyPath = previousKeyPath;
3397 task.treeContext = previousTreeContext;
@@ -3435,7 +3443,9 @@ function renderNode(
3443 // Restore the context. We assume that this will be restored by the inner
3444 // functions in case nothing throws so we don't use "finally" here.
3445 task.formatContext = previousFormatContext;
3438 - task.legacyContext = previousLegacyContext;
3446 + if (!disableLegacyContext) {
3447 + task.legacyContext = previousLegacyContext;
3448 + }
3449 task.context = previousContext;
3450 task.keyPath = previousKeyPath;
3451 task.treeContext = previousTreeContext;
@@ -3469,7 +3479,9 @@ function renderNode(
3479 // Restore the context. We assume that this will be restored by the inner
3480 // functions in case nothing throws so we don't use "finally" here.
3481 task.formatContext = previousFormatContext;
3472 - task.legacyContext = previousLegacyContext;
3482 + if (!disableLegacyContext) {
3483 + task.legacyContext = previousLegacyContext;
3484 + }
3485 task.context = previousContext;
3486 task.keyPath = previousKeyPath;
3487 task.treeContext = previousTreeContext;
@@ -3485,7 +3497,9 @@ function renderNode(
3497 // Restore the context. We assume that this will be restored by the inner
3498 // functions in case nothing throws so we don't use "finally" here.
3499 task.formatContext = previousFormatContext;
3488 - task.legacyContext = previousLegacyContext;
3500 + if (!disableLegacyContext) {
3501 + task.legacyContext = previousLegacyContext;
3502 + }
3503 task.context = previousContext;
3504 task.keyPath = previousKeyPath;
3505 task.treeContext = previousTreeContext;