Skip to content

Commit

Permalink
Update only parents that may be inconsistent
Browse files Browse the repository at this point in the history
  • Loading branch information
okmttdhr committed Jan 17, 2022
1 parent c17e455 commit 3a1aa3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions packages/react-reconciler/src/ReactFiberNewContext.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -293,7 +299,7 @@ function propagateContextChange_eager<T>(
) {
// 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.
Expand Down Expand Up @@ -381,7 +387,11 @@ function propagateContextChanges<T>(
// 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);
}
Expand Down
14 changes: 12 additions & 2 deletions packages/react-reconciler/src/ReactFiberNewContext.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -293,7 +299,7 @@ function propagateContextChange_eager<T>(
) {
// 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.
Expand Down Expand Up @@ -381,7 +387,11 @@ function propagateContextChanges<T>(
// 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);
}
Expand Down

0 comments on commit 3a1aa3e

Please sign in to comment.