Skip to content

Commit e3c5596

Browse files
committed
Update only parents that may be inconsistent
1 parent c17e455 commit e3c5596

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

packages/react-reconciler/src/ReactFiberNewContext.new.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function popProvider(
142142
export function scheduleWorkOnParentPath(
143143
parent: Fiber | null,
144144
renderLanes: Lanes,
145+
stopAt?: Fiber | null = null,
145146
) {
146147
// Update the child lanes of all the ancestors, including the alternates.
147148
let node = parent;
@@ -160,6 +161,11 @@ export function scheduleWorkOnParentPath(
160161
} else {
161162
// Neither alternate was updated, which means the rest of the
162163
// ancestor path already has sufficient priority.
164+
if (stopAt === null) {
165+
break;
166+
}
167+
}
168+
if (stopAt && node === stopAt) {
163169
break;
164170
}
165171
node = node.return;
@@ -285,16 +291,8 @@ function propagateContextChange_eager<T>(
285291
// because we want to schedule this fiber as having work
286292
// on its children. We'll use the childLanes on
287293
// this fiber to indicate that a context has changed.
288-
scheduleWorkOnParentPath(parentSuspense, renderLanes);
294+
scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense);
289295
nextFiber = fiber.sibling;
290-
} else if (
291-
fiber.tag === SuspenseComponent &&
292-
workInProgress.tag === ContextProvider
293-
) {
294-
// We don't know if it will have any context consumers in it.
295-
// Schedule this fiber as having work on its children.
296-
scheduleWorkOnParentPath(fiber.child, renderLanes);
297-
nextFiber = fiber.child;
298296
} else {
299297
// Traverse down.
300298
nextFiber = fiber.child;
@@ -381,7 +379,11 @@ function propagateContextChanges<T>(
381379
// on its children. We'll use the childLanes on
382380
// this fiber to indicate that a context has changed.
383381
const primaryChildFragment = workInProgress.child;
384-
scheduleWorkOnParentPath(primaryChildFragment, renderLanes);
382+
scheduleWorkOnParentPath(
383+
primaryChildFragment,
384+
renderLanes,
385+
workInProgress,
386+
);
385387
} else {
386388
scheduleWorkOnParentPath(consumer.return, renderLanes);
387389
}
@@ -425,7 +427,7 @@ function propagateContextChanges<T>(
425427
// because we want to schedule this fiber as having work
426428
// on its children. We'll use the childLanes on
427429
// this fiber to indicate that a context has changed.
428-
scheduleWorkOnParentPath(parentSuspense, renderLanes);
430+
scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense);
429431
nextFiber = null;
430432
} else {
431433
// Traverse down.

packages/react-reconciler/src/ReactFiberNewContext.old.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export function popProvider(
142142
export function scheduleWorkOnParentPath(
143143
parent: Fiber | null,
144144
renderLanes: Lanes,
145+
stopAt?: Fiber | null = null,
145146
) {
146147
// Update the child lanes of all the ancestors, including the alternates.
147148
let node = parent;
@@ -160,6 +161,11 @@ export function scheduleWorkOnParentPath(
160161
} else {
161162
// Neither alternate was updated, which means the rest of the
162163
// ancestor path already has sufficient priority.
164+
if (stopAt === null) {
165+
break;
166+
}
167+
}
168+
if (stopAt && node === stopAt) {
163169
break;
164170
}
165171
node = node.return;
@@ -285,16 +291,8 @@ function propagateContextChange_eager<T>(
285291
// because we want to schedule this fiber as having work
286292
// on its children. We'll use the childLanes on
287293
// this fiber to indicate that a context has changed.
288-
scheduleWorkOnParentPath(parentSuspense, renderLanes);
294+
scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense);
289295
nextFiber = fiber.sibling;
290-
} else if (
291-
fiber.tag === SuspenseComponent &&
292-
workInProgress.tag === ContextProvider
293-
) {
294-
// We don't know if it will have any context consumers in it.
295-
// Schedule this fiber as having work on its children.
296-
scheduleWorkOnParentPath(fiber.child, renderLanes);
297-
nextFiber = fiber.child;
298296
} else {
299297
// Traverse down.
300298
nextFiber = fiber.child;
@@ -381,7 +379,11 @@ function propagateContextChanges<T>(
381379
// on its children. We'll use the childLanes on
382380
// this fiber to indicate that a context has changed.
383381
const primaryChildFragment = workInProgress.child;
384-
scheduleWorkOnParentPath(primaryChildFragment, renderLanes);
382+
scheduleWorkOnParentPath(
383+
primaryChildFragment,
384+
renderLanes,
385+
workInProgress,
386+
);
385387
} else {
386388
scheduleWorkOnParentPath(consumer.return, renderLanes);
387389
}
@@ -425,7 +427,7 @@ function propagateContextChanges<T>(
425427
// because we want to schedule this fiber as having work
426428
// on its children. We'll use the childLanes on
427429
// this fiber to indicate that a context has changed.
428-
scheduleWorkOnParentPath(parentSuspense, renderLanes);
430+
scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense);
429431
nextFiber = null;
430432
} else {
431433
// Traverse down.

0 commit comments

Comments
 (0)