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 ba7d2ed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 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 @@ -285,15 +291,15 @@ function propagateContextChange_eager<T>(
// 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 &&
workInProgress.tag === ContextProvider
) {
// 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.
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 Expand Up @@ -425,7 +435,7 @@ function propagateContextChanges<T>(
// 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.
Expand Down
18 changes: 14 additions & 4 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 @@ -285,15 +291,15 @@ function propagateContextChange_eager<T>(
// 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 &&
workInProgress.tag === ContextProvider
) {
// 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.
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 Expand Up @@ -425,7 +435,7 @@ function propagateContextChanges<T>(
// 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.
Expand Down

0 comments on commit ba7d2ed

Please sign in to comment.