Skip to content

Commit ba7d2ed

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

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

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

Lines changed: 14 additions & 4 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,15 +291,15 @@ 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;
290296
} else if (
291297
fiber.tag === SuspenseComponent &&
292298
workInProgress.tag === ContextProvider
293299
) {
294300
// We don't know if it will have any context consumers in it.
295301
// Schedule this fiber as having work on its children.
296-
scheduleWorkOnParentPath(fiber.child, renderLanes);
302+
scheduleWorkOnParentPath(fiber.child, renderLanes, fiber);
297303
nextFiber = fiber.child;
298304
} else {
299305
// Traverse down.
@@ -381,7 +387,11 @@ function propagateContextChanges<T>(
381387
// on its children. We'll use the childLanes on
382388
// this fiber to indicate that a context has changed.
383389
const primaryChildFragment = workInProgress.child;
384-
scheduleWorkOnParentPath(primaryChildFragment, renderLanes);
390+
scheduleWorkOnParentPath(
391+
primaryChildFragment,
392+
renderLanes,
393+
workInProgress,
394+
);
385395
} else {
386396
scheduleWorkOnParentPath(consumer.return, renderLanes);
387397
}
@@ -425,7 +435,7 @@ function propagateContextChanges<T>(
425435
// because we want to schedule this fiber as having work
426436
// on its children. We'll use the childLanes on
427437
// this fiber to indicate that a context has changed.
428-
scheduleWorkOnParentPath(parentSuspense, renderLanes);
438+
scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense);
429439
nextFiber = null;
430440
} else {
431441
// Traverse down.

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

Lines changed: 14 additions & 4 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,15 +291,15 @@ 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;
290296
} else if (
291297
fiber.tag === SuspenseComponent &&
292298
workInProgress.tag === ContextProvider
293299
) {
294300
// We don't know if it will have any context consumers in it.
295301
// Schedule this fiber as having work on its children.
296-
scheduleWorkOnParentPath(fiber.child, renderLanes);
302+
scheduleWorkOnParentPath(fiber.child, renderLanes, fiber);
297303
nextFiber = fiber.child;
298304
} else {
299305
// Traverse down.
@@ -381,7 +387,11 @@ function propagateContextChanges<T>(
381387
// on its children. We'll use the childLanes on
382388
// this fiber to indicate that a context has changed.
383389
const primaryChildFragment = workInProgress.child;
384-
scheduleWorkOnParentPath(primaryChildFragment, renderLanes);
390+
scheduleWorkOnParentPath(
391+
primaryChildFragment,
392+
renderLanes,
393+
workInProgress,
394+
);
385395
} else {
386396
scheduleWorkOnParentPath(consumer.return, renderLanes);
387397
}
@@ -425,7 +435,7 @@ function propagateContextChanges<T>(
425435
// because we want to schedule this fiber as having work
426436
// on its children. We'll use the childLanes on
427437
// this fiber to indicate that a context has changed.
428-
scheduleWorkOnParentPath(parentSuspense, renderLanes);
438+
scheduleWorkOnParentPath(parentSuspense, renderLanes, parentSuspense);
429439
nextFiber = null;
430440
} else {
431441
// Traverse down.

0 commit comments

Comments
 (0)