From 3a1aa3eb323cd4d62420123c87e449562be62cdb Mon Sep 17 00:00:00 2001 From: okmttdhr Date: Mon, 17 Jan 2022 11:41:55 +0900 Subject: [PATCH] Update only parents that may be inconsistent --- .../src/ReactFiberNewContext.new.js | 14 ++++++++++++-- .../src/ReactFiberNewContext.old.js | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberNewContext.new.js b/packages/react-reconciler/src/ReactFiberNewContext.new.js index d478369e64135..e5aee6675db99 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 e55a73ef42b2a..a2587966c5e4d 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); }