diff --git a/packages/react-reconciler/src/ReactFiberNewContext.new.js b/packages/react-reconciler/src/ReactFiberNewContext.new.js index d478369e6413..e5aee6675db9 100644 --- a/packages/react-reconciler/src/ReactFiberNewContext.new.js +++ b/packages/react-reconciler/src/ReactFiberNewContext.new.js @@ -142,6 +142,7 @@ export function popProvider( export function scheduleWorkOnParentPath( parent: Fiber | null, renderLanes: Lanes, + stopAt?: Fiber | null = null, ) { // Update the child lanes of all the ancestors, including the alternates. let node = parent; @@ -160,6 +161,11 @@ export function scheduleWorkOnParentPath( } else { // Neither alternate was updated, which means the rest of the // ancestor path already has sufficient priority. + if (stopAt === null) { + break; + } + } + if (stopAt && node === stopAt) { break; } node = node.return; @@ -293,7 +299,7 @@ function propagateContextChange_eager( ) { // We don't know if it will have any context consumers in it. // Schedule this fiber as having work on its children. - scheduleWorkOnParentPath(fiber.child, renderLanes); + scheduleWorkOnParentPath(fiber.child, renderLanes, workInProgress); nextFiber = fiber.child; } else { // Traverse down. @@ -381,7 +387,11 @@ function propagateContextChanges( // on its children. We'll use the childLanes on // this fiber to indicate that a context has changed. const primaryChildFragment = workInProgress.child; - scheduleWorkOnParentPath(primaryChildFragment, renderLanes); + scheduleWorkOnParentPath( + primaryChildFragment, + renderLanes, + workInProgress, + ); } else { scheduleWorkOnParentPath(consumer.return, renderLanes); } diff --git a/packages/react-reconciler/src/ReactFiberNewContext.old.js b/packages/react-reconciler/src/ReactFiberNewContext.old.js index e55a73ef42b2..a2587966c5e4 100644 --- a/packages/react-reconciler/src/ReactFiberNewContext.old.js +++ b/packages/react-reconciler/src/ReactFiberNewContext.old.js @@ -142,6 +142,7 @@ export function popProvider( export function scheduleWorkOnParentPath( parent: Fiber | null, renderLanes: Lanes, + stopAt?: Fiber | null = null, ) { // Update the child lanes of all the ancestors, including the alternates. let node = parent; @@ -160,6 +161,11 @@ export function scheduleWorkOnParentPath( } else { // Neither alternate was updated, which means the rest of the // ancestor path already has sufficient priority. + if (stopAt === null) { + break; + } + } + if (stopAt && node === stopAt) { break; } node = node.return; @@ -293,7 +299,7 @@ function propagateContextChange_eager( ) { // We don't know if it will have any context consumers in it. // Schedule this fiber as having work on its children. - scheduleWorkOnParentPath(fiber.child, renderLanes); + scheduleWorkOnParentPath(fiber.child, renderLanes, workInProgress); nextFiber = fiber.child; } else { // Traverse down. @@ -381,7 +387,11 @@ function propagateContextChanges( // on its children. We'll use the childLanes on // this fiber to indicate that a context has changed. const primaryChildFragment = workInProgress.child; - scheduleWorkOnParentPath(primaryChildFragment, renderLanes); + scheduleWorkOnParentPath( + primaryChildFragment, + renderLanes, + workInProgress, + ); } else { scheduleWorkOnParentPath(consumer.return, renderLanes); }