From ba7d2ed96aec02a6d2370fddffecd9366a563145 Mon Sep 17 00:00:00 2001 From: okmttdhr Date: Mon, 17 Jan 2022 11:32:53 +0900 Subject: [PATCH] Update only parents that may be inconsistent --- .../src/ReactFiberNewContext.new.js | 18 ++++++++++++++---- .../src/ReactFiberNewContext.old.js | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberNewContext.new.js b/packages/react-reconciler/src/ReactFiberNewContext.new.js index d478369e64135..2773196ff374c 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; @@ -285,7 +291,7 @@ function propagateContextChange_eager( // because we want to schedule this fiber as having work // on its children. We'll use the childLanes on // this fiber to indicate that a context has changed. - scheduleWorkOnParentPath(parentSuspense, renderLanes); + scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense); nextFiber = fiber.sibling; } else if ( fiber.tag === SuspenseComponent && @@ -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, fiber); 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); } @@ -425,7 +435,7 @@ function propagateContextChanges( // because we want to schedule this fiber as having work // on its children. We'll use the childLanes on // this fiber to indicate that a context has changed. - scheduleWorkOnParentPath(parentSuspense, renderLanes); + scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense); nextFiber = null; } else { // Traverse down. diff --git a/packages/react-reconciler/src/ReactFiberNewContext.old.js b/packages/react-reconciler/src/ReactFiberNewContext.old.js index e55a73ef42b2a..4c3349cdd3c66 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; @@ -285,7 +291,7 @@ function propagateContextChange_eager( // because we want to schedule this fiber as having work // on its children. We'll use the childLanes on // this fiber to indicate that a context has changed. - scheduleWorkOnParentPath(parentSuspense, renderLanes); + scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense); nextFiber = fiber.sibling; } else if ( fiber.tag === SuspenseComponent && @@ -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, fiber); 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); } @@ -425,7 +435,7 @@ function propagateContextChanges( // because we want to schedule this fiber as having work // on its children. We'll use the childLanes on // this fiber to indicate that a context has changed. - scheduleWorkOnParentPath(parentSuspense, renderLanes); + scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense); nextFiber = null; } else { // Traverse down.