Skip to content

Commit 6d2a97a

Browse files
authored
[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.
1 parent 100dfd7 commit 6d2a97a

File tree

1 file changed

+36
-22
lines changed

1 file changed

+36
-22
lines changed

packages/react-server/src/ReactFizzServer.js

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ type RenderTask = {
243243
abortSet: Set<Task>, // the abortable set that this task belongs to
244244
keyPath: Root | KeyNode, // the path of all parent keys currently rendering
245245
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
247246
context: ContextSnapshot, // the current new context that this task is executing in
248247
treeContext: TreeContext, // the current tree context that this task is executing in
249248
componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
250249
thenableState: null | ThenableState,
251250
isFallback: boolean, // whether this task is rendering inside a fallback tree
251+
legacyContext: LegacyContext, // the current legacy context that this task is executing in
252252
// DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
253253
// Consider splitting into multiple objects or consolidating some fields.
254254
};
@@ -272,12 +272,12 @@ type ReplayTask = {
272272
abortSet: Set<Task>, // the abortable set that this task belongs to
273273
keyPath: Root | KeyNode, // the path of all parent keys currently rendering
274274
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
276275
context: ContextSnapshot, // the current new context that this task is executing in
277276
treeContext: TreeContext, // the current tree context that this task is executing in
278277
componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
279278
thenableState: null | ThenableState,
280279
isFallback: boolean, // whether this task is rendering inside a fallback tree
280+
legacyContext: LegacyContext, // the current legacy context that this task is executing in
281281
// DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
282282
// Consider splitting into multiple objects or consolidating some fields.
283283
};
@@ -462,11 +462,11 @@ function RequestInstance(
462462
abortSet,
463463
null,
464464
rootFormatContext,
465-
emptyContextObject,
466465
rootContextSnapshot,
467466
emptyTreeContext,
468467
null,
469468
false,
469+
emptyContextObject,
470470
);
471471
pingedTasks.push(rootTask);
472472
}
@@ -604,11 +604,11 @@ export function resumeRequest(
604604
abortSet,
605605
null,
606606
postponedState.rootFormatContext,
607-
emptyContextObject,
608607
rootContextSnapshot,
609608
emptyTreeContext,
610609
null,
611610
false,
611+
emptyContextObject,
612612
);
613613
pingedTasks.push(rootTask);
614614
return request;
@@ -630,11 +630,11 @@ export function resumeRequest(
630630
abortSet,
631631
null,
632632
postponedState.rootFormatContext,
633-
emptyContextObject,
634633
rootContextSnapshot,
635634
emptyTreeContext,
636635
null,
637636
false,
637+
emptyContextObject,
638638
);
639639
pingedTasks.push(rootTask);
640640
return request;
@@ -698,19 +698,19 @@ function createRenderTask(
698698
abortSet: Set<Task>,
699699
keyPath: Root | KeyNode,
700700
formatContext: FormatContext,
701-
legacyContext: LegacyContext,
702701
context: ContextSnapshot,
703702
treeContext: TreeContext,
704703
componentStack: null | ComponentStackNode,
705704
isFallback: boolean,
705+
legacyContext: LegacyContext,
706706
): RenderTask {
707707
request.allPendingTasks++;
708708
if (blockedBoundary === null) {
709709
request.pendingRootTasks++;
710710
} else {
711711
blockedBoundary.pendingTasks++;
712712
}
713-
const task: RenderTask = {
713+
const task: RenderTask = ({
714714
replay: null,
715715
node,
716716
childIndex,
@@ -721,13 +721,15 @@ function createRenderTask(
721721
abortSet,
722722
keyPath,
723723
formatContext,
724-
legacyContext,
725724
context,
726725
treeContext,
727726
componentStack,
728727
thenableState,
729728
isFallback,
730-
};
729+
}: any);
730+
if (!disableLegacyContext) {
731+
task.legacyContext = legacyContext;
732+
}
731733
abortSet.add(task);
732734
return task;
733735
}
@@ -743,11 +745,11 @@ function createReplayTask(
743745
abortSet: Set<Task>,
744746
keyPath: Root | KeyNode,
745747
formatContext: FormatContext,
746-
legacyContext: LegacyContext,
747748
context: ContextSnapshot,
748749
treeContext: TreeContext,
749750
componentStack: null | ComponentStackNode,
750751
isFallback: boolean,
752+
legacyContext: LegacyContext,
751753
): ReplayTask {
752754
request.allPendingTasks++;
753755
if (blockedBoundary === null) {
@@ -756,7 +758,7 @@ function createReplayTask(
756758
blockedBoundary.pendingTasks++;
757759
}
758760
replay.pendingTasks++;
759-
const task: ReplayTask = {
761+
const task: ReplayTask = ({
760762
replay,
761763
node,
762764
childIndex,
@@ -767,13 +769,15 @@ function createReplayTask(
767769
abortSet,
768770
keyPath,
769771
formatContext,
770-
legacyContext,
771772
context,
772773
treeContext,
773774
componentStack,
774775
thenableState,
775776
isFallback,
776-
};
777+
}: any);
778+
if (!disableLegacyContext) {
779+
task.legacyContext = legacyContext;
780+
}
777781
abortSet.add(task);
778782
return task;
779783
}
@@ -1188,13 +1192,13 @@ function renderSuspenseBoundary(
11881192
fallbackAbortSet,
11891193
fallbackKeyPath,
11901194
task.formatContext,
1191-
task.legacyContext,
11921195
task.context,
11931196
task.treeContext,
11941197
// This stack should be the Suspense boundary stack because while the fallback is actually a child segment
11951198
// of the parent boundary from a component standpoint the fallback is a child of the Suspense boundary itself
11961199
suspenseComponentStack,
11971200
true,
1201+
!disableLegacyContext ? task.legacyContext : emptyContextObject,
11981202
);
11991203
// TODO: This should be queued at a separate lower priority queue so that we only work
12001204
// on preparing fallbacks if we don't have any more main content to task on.
@@ -1328,13 +1332,13 @@ function replaySuspenseBoundary(
13281332
fallbackAbortSet,
13291333
fallbackKeyPath,
13301334
task.formatContext,
1331-
task.legacyContext,
13321335
task.context,
13331336
task.treeContext,
13341337
// This stack should be the Suspense boundary stack because while the fallback is actually a child segment
13351338
// of the parent boundary from a component standpoint the fallback is a child of the Suspense boundary itself
13361339
suspenseComponentStack,
13371340
true,
1341+
!disableLegacyContext ? task.legacyContext : emptyContextObject,
13381342
);
13391343
// TODO: This should be queued at a separate lower priority queue so that we only work
13401344
// on preparing fallbacks if we don't have any more main content to task on.
@@ -3271,13 +3275,13 @@ function spawnNewSuspendedReplayTask(
32713275
task.abortSet,
32723276
task.keyPath,
32733277
task.formatContext,
3274-
task.legacyContext,
32753278
task.context,
32763279
task.treeContext,
32773280
// We pop one task off the stack because the node that suspended will be tried again,
32783281
// which will add it back onto the stack.
32793282
task.componentStack !== null ? task.componentStack.parent : null,
32803283
task.isFallback,
3284+
!disableLegacyContext ? task.legacyContext : emptyContextObject,
32813285
);
32823286

32833287
const ping = newTask.ping;
@@ -3317,13 +3321,13 @@ function spawnNewSuspendedRenderTask(
33173321
task.abortSet,
33183322
task.keyPath,
33193323
task.formatContext,
3320-
task.legacyContext,
33213324
task.context,
33223325
task.treeContext,
33233326
// We pop one task off the stack because the node that suspended will be tried again,
33243327
// which will add it back onto the stack.
33253328
task.componentStack !== null ? task.componentStack.parent : null,
33263329
task.isFallback,
3330+
!disableLegacyContext ? task.legacyContext : emptyContextObject,
33273331
);
33283332

33293333
const ping = newTask.ping;
@@ -3341,7 +3345,9 @@ function renderNode(
33413345
// Snapshot the current context in case something throws to interrupt the
33423346
// process.
33433347
const previousFormatContext = task.formatContext;
3344-
const previousLegacyContext = task.legacyContext;
3348+
const previousLegacyContext = !disableLegacyContext
3349+
? task.legacyContext
3350+
: emptyContextObject;
33453351
const previousContext = task.context;
33463352
const previousKeyPath = task.keyPath;
33473353
const previousTreeContext = task.treeContext;
@@ -3383,7 +3389,9 @@ function renderNode(
33833389
// Restore the context. We assume that this will be restored by the inner
33843390
// functions in case nothing throws so we don't use "finally" here.
33853391
task.formatContext = previousFormatContext;
3386-
task.legacyContext = previousLegacyContext;
3392+
if (!disableLegacyContext) {
3393+
task.legacyContext = previousLegacyContext;
3394+
}
33873395
task.context = previousContext;
33883396
task.keyPath = previousKeyPath;
33893397
task.treeContext = previousTreeContext;
@@ -3435,7 +3443,9 @@ function renderNode(
34353443
// Restore the context. We assume that this will be restored by the inner
34363444
// functions in case nothing throws so we don't use "finally" here.
34373445
task.formatContext = previousFormatContext;
3438-
task.legacyContext = previousLegacyContext;
3446+
if (!disableLegacyContext) {
3447+
task.legacyContext = previousLegacyContext;
3448+
}
34393449
task.context = previousContext;
34403450
task.keyPath = previousKeyPath;
34413451
task.treeContext = previousTreeContext;
@@ -3469,7 +3479,9 @@ function renderNode(
34693479
// Restore the context. We assume that this will be restored by the inner
34703480
// functions in case nothing throws so we don't use "finally" here.
34713481
task.formatContext = previousFormatContext;
3472-
task.legacyContext = previousLegacyContext;
3482+
if (!disableLegacyContext) {
3483+
task.legacyContext = previousLegacyContext;
3484+
}
34733485
task.context = previousContext;
34743486
task.keyPath = previousKeyPath;
34753487
task.treeContext = previousTreeContext;
@@ -3485,7 +3497,9 @@ function renderNode(
34853497
// Restore the context. We assume that this will be restored by the inner
34863498
// functions in case nothing throws so we don't use "finally" here.
34873499
task.formatContext = previousFormatContext;
3488-
task.legacyContext = previousLegacyContext;
3500+
if (!disableLegacyContext) {
3501+
task.legacyContext = previousLegacyContext;
3502+
}
34893503
task.context = previousContext;
34903504
task.keyPath = previousKeyPath;
34913505
task.treeContext = previousTreeContext;

0 commit comments

Comments
 (0)