138
}
139
}
140
141
-export function scheduleWorkOnParentPath(
141
+export function scheduleContextWorkOnParentPath(
142
parent: Fiber | null,
143
renderLanes: Lanes,
144
+ propagationRoot: Fiber,
145
) {
146
// Update the child lanes of all the ancestors, including the alternates.
147
let node = parent;
158
) {
159
alternate.childLanes = mergeLanes(alternate.childLanes, renderLanes);
160
} else {
160
- // Neither alternate was updated, which means the rest of the
161
+ // Neither alternate was updated.
162
+ // Normally, this would mean that the rest of the
163
// ancestor path already has sufficient priority.
164
+ // However, this is not necessarily true inside offscreen
165
+ // or fallback trees because childLanes may be inconsistent
166
+ // with the surroundings. This is why we continue the loop.
167
+ }
168
+ if (node === propagationRoot) {
169
break;
170
}
171
node = node.return;
172
}
173
+ if (__DEV__) {
174
+ if (node !== propagationRoot) {
175
+ console.error(
176
+ 'Expected to find the propagation root when scheduling context work. ' +
177
+ 'This error is likely caused by a bug in React. Please file an issue.',
178
+ );
179
+ }
180
+ }
181
}
182
183
export function propagateContextChange<T>(
261
if (alternate !== null) {
262
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
263
}
249
- scheduleWorkOnParentPath(fiber.return, renderLanes);
264
+ scheduleContextWorkOnParentPath(
265
+ fiber.return,
266
+ renderLanes,
267
+ workInProgress,
268
+ );
269
270
// Mark the updated lanes on the list, too.
271
list.lanes = mergeLanes(list.lanes, renderLanes);
303
// because we want to schedule this fiber as having work
304
// on its children. We'll use the childLanes on
305
// this fiber to indicate that a context has changed.
287
- scheduleWorkOnParentPath(parentSuspense, renderLanes);
306
+ scheduleContextWorkOnParentPath(
307
+ parentSuspense,
308
+ renderLanes,
309
+ workInProgress,
310
+ );
311
nextFiber = fiber.sibling;
312
} else {
313
// Traverse down.
388
if (alternate !== null) {
389
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
390
}
368
- scheduleWorkOnParentPath(consumer.return, renderLanes);
391
+ scheduleContextWorkOnParentPath(
392
+ consumer.return,
393
+ renderLanes,
394
+ workInProgress,
395
+ );
396
397
if (!forcePropagateEntireTree) {
398
// During lazy propagation, when we find a match, we can defer
433
// because we want to schedule this fiber as having work
434
// on its children. We'll use the childLanes on
435
// this fiber to indicate that a context has changed.
409
- scheduleWorkOnParentPath(parentSuspense, renderLanes);
436
+ scheduleContextWorkOnParentPath(
437
+ parentSuspense,
438
+ renderLanes,
439
+ workInProgress,
440
+ );
441
nextFiber = null;
442
} else {
443
// Traverse down.