Skip to content

Commit 3a1aa3e

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

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

Lines changed: 12 additions & 2 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;
@@ -293,7 +299,7 @@ function propagateContextChange_eager<T>(
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, workInProgress);
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
}

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

Lines changed: 12 additions & 2 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;
@@ -293,7 +299,7 @@ function propagateContextChange_eager<T>(
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, workInProgress);
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
}

0 commit comments

Comments
 (0)