Skip to content

Commit

Permalink
Gate legacyContext field on disableLegacyContext
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Jul 1, 2024
1 parent 100dfd7 commit b21603f
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ type RenderTask = {
abortSet: Set<Task>, // the abortable set that this task belongs to
keyPath: Root | KeyNode, // the path of all parent keys currently rendering
formatContext: FormatContext, // the format's specific context (e.g. HTML/SVG/MathML)
legacyContext: LegacyContext, // the current legacy context that this task is executing in
context: ContextSnapshot, // the current new context that this task is executing in
treeContext: TreeContext, // the current tree context that this task is executing in
componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
thenableState: null | ThenableState,
isFallback: boolean, // whether this task is rendering inside a fallback tree
legacyContext: LegacyContext, // the current legacy context that this task is executing in
// DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
// Consider splitting into multiple objects or consolidating some fields.
};
Expand All @@ -272,12 +272,12 @@ type ReplayTask = {
abortSet: Set<Task>, // the abortable set that this task belongs to
keyPath: Root | KeyNode, // the path of all parent keys currently rendering
formatContext: FormatContext, // the format's specific context (e.g. HTML/SVG/MathML)
legacyContext: LegacyContext, // the current legacy context that this task is executing in
context: ContextSnapshot, // the current new context that this task is executing in
treeContext: TreeContext, // the current tree context that this task is executing in
componentStack: null | ComponentStackNode, // stack frame description of the currently rendering component
thenableState: null | ThenableState,
isFallback: boolean, // whether this task is rendering inside a fallback tree
legacyContext: LegacyContext, // the current legacy context that this task is executing in
// DON'T ANY MORE FIELDS. We at 16 already which otherwise requires converting to a constructor.
// Consider splitting into multiple objects or consolidating some fields.
};
Expand Down Expand Up @@ -710,7 +710,7 @@ function createRenderTask(
} else {
blockedBoundary.pendingTasks++;
}
const task: RenderTask = {
const task: RenderTask = ({
replay: null,
node,
childIndex,
Expand All @@ -721,13 +721,15 @@ function createRenderTask(
abortSet,
keyPath,
formatContext,
legacyContext,
context,
treeContext,
componentStack,
thenableState,
isFallback,
};
}: any);
if (!disableLegacyContext) {
task.legacyContext = legacyContext;
}
abortSet.add(task);
return task;
}
Expand Down Expand Up @@ -756,7 +758,7 @@ function createReplayTask(
blockedBoundary.pendingTasks++;
}
replay.pendingTasks++;
const task: ReplayTask = {
const task: ReplayTask = ({
replay,
node,
childIndex,
Expand All @@ -767,13 +769,15 @@ function createReplayTask(
abortSet,
keyPath,
formatContext,
legacyContext,
context,
treeContext,
componentStack,
thenableState,
isFallback,
};
}: any);
if (!disableLegacyContext) {
task.legacyContext = legacyContext;
}
abortSet.add(task);
return task;
}
Expand Down Expand Up @@ -1188,7 +1192,7 @@ function renderSuspenseBoundary(
fallbackAbortSet,
fallbackKeyPath,
task.formatContext,
task.legacyContext,
!disableLegacyContext ? task.legacyContext : emptyContextObject,
task.context,
task.treeContext,
// This stack should be the Suspense boundary stack because while the fallback is actually a child segment
Expand Down Expand Up @@ -1328,7 +1332,7 @@ function replaySuspenseBoundary(
fallbackAbortSet,
fallbackKeyPath,
task.formatContext,
task.legacyContext,
!disableLegacyContext ? task.legacyContext : emptyContextObject,
task.context,
task.treeContext,
// This stack should be the Suspense boundary stack because while the fallback is actually a child segment
Expand Down Expand Up @@ -3271,7 +3275,7 @@ function spawnNewSuspendedReplayTask(
task.abortSet,
task.keyPath,
task.formatContext,
task.legacyContext,
!disableLegacyContext ? task.legacyContext : emptyContextObject,
task.context,
task.treeContext,
// We pop one task off the stack because the node that suspended will be tried again,
Expand Down Expand Up @@ -3317,7 +3321,7 @@ function spawnNewSuspendedRenderTask(
task.abortSet,
task.keyPath,
task.formatContext,
task.legacyContext,
!disableLegacyContext ? task.legacyContext : emptyContextObject,
task.context,
task.treeContext,
// We pop one task off the stack because the node that suspended will be tried again,
Expand All @@ -3341,7 +3345,9 @@ function renderNode(
// Snapshot the current context in case something throws to interrupt the
// process.
const previousFormatContext = task.formatContext;
const previousLegacyContext = task.legacyContext;
const previousLegacyContext = !disableLegacyContext
? task.legacyContext
: emptyContextObject;
const previousContext = task.context;
const previousKeyPath = task.keyPath;
const previousTreeContext = task.treeContext;
Expand Down Expand Up @@ -3383,7 +3389,9 @@ function renderNode(
// Restore the context. We assume that this will be restored by the inner
// functions in case nothing throws so we don't use "finally" here.
task.formatContext = previousFormatContext;
task.legacyContext = previousLegacyContext;
if (!disableLegacyContext) {
task.legacyContext = previousLegacyContext;
}
task.context = previousContext;
task.keyPath = previousKeyPath;
task.treeContext = previousTreeContext;
Expand Down Expand Up @@ -3435,7 +3443,9 @@ function renderNode(
// Restore the context. We assume that this will be restored by the inner
// functions in case nothing throws so we don't use "finally" here.
task.formatContext = previousFormatContext;
task.legacyContext = previousLegacyContext;
if (!disableLegacyContext) {
task.legacyContext = previousLegacyContext;
}
task.context = previousContext;
task.keyPath = previousKeyPath;
task.treeContext = previousTreeContext;
Expand Down Expand Up @@ -3469,7 +3479,9 @@ function renderNode(
// Restore the context. We assume that this will be restored by the inner
// functions in case nothing throws so we don't use "finally" here.
task.formatContext = previousFormatContext;
task.legacyContext = previousLegacyContext;
if (!disableLegacyContext) {
task.legacyContext = previousLegacyContext;
}
task.context = previousContext;
task.keyPath = previousKeyPath;
task.treeContext = previousTreeContext;
Expand All @@ -3485,7 +3497,9 @@ function renderNode(
// Restore the context. We assume that this will be restored by the inner
// functions in case nothing throws so we don't use "finally" here.
task.formatContext = previousFormatContext;
task.legacyContext = previousLegacyContext;
if (!disableLegacyContext) {
task.legacyContext = previousLegacyContext;
}
task.context = previousContext;
task.keyPath = previousKeyPath;
task.treeContext = previousTreeContext;
Expand Down

0 comments on commit b21603f

Please sign in to comment.