Skip to content

Commit

Permalink
Schedule work to update Context.Consumer inside Suspense
Browse files Browse the repository at this point in the history
  • Loading branch information
okmttdhr committed May 9, 2021
1 parent f55e80e commit ed58992
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion packages/react-reconciler/src/ReactFiberNewContext.new.js
Expand Up @@ -23,6 +23,7 @@ import {
ContextProvider,
ClassComponent,
DehydratedFragment,
SuspenseComponent,
} from './ReactWorkTags';
import {
NoLanes,
Expand Down Expand Up @@ -284,6 +285,14 @@ function propagateContextChange_eager<T>(
// this fiber to indicate that a context has changed.
scheduleWorkOnParentPath(parentSuspense, renderLanes);
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);
nextFiber = fiber.child;
} else {
// Traverse down.
nextFiber = fiber.child;
Expand Down Expand Up @@ -363,7 +372,17 @@ function propagateContextChanges<T>(
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(consumer.return, renderLanes);

if (workInProgress.tag === SuspenseComponent) {
// This is intentionally passing this fiber as the parent
// 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.
const primaryChildFragment = workInProgress.child;
scheduleWorkOnParentPath(primaryChildFragment, renderLanes);
} else {
scheduleWorkOnParentPath(consumer.return, renderLanes);
}

if (!forcePropagateEntireTree) {
// During lazy propagation, when we find a match, we can defer
Expand Down
21 changes: 20 additions & 1 deletion packages/react-reconciler/src/ReactFiberNewContext.old.js
Expand Up @@ -23,6 +23,7 @@ import {
ContextProvider,
ClassComponent,
DehydratedFragment,
SuspenseComponent,
} from './ReactWorkTags';
import {
NoLanes,
Expand Down Expand Up @@ -284,6 +285,14 @@ function propagateContextChange_eager<T>(
// this fiber to indicate that a context has changed.
scheduleWorkOnParentPath(parentSuspense, renderLanes);
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);
nextFiber = fiber.child;
} else {
// Traverse down.
nextFiber = fiber.child;
Expand Down Expand Up @@ -363,7 +372,17 @@ function propagateContextChanges<T>(
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(consumer.return, renderLanes);

if (workInProgress.tag === SuspenseComponent) {
// This is intentionally passing this fiber as the parent
// 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.
const primaryChildFragment = workInProgress.child;
scheduleWorkOnParentPath(primaryChildFragment, renderLanes);
} else {
scheduleWorkOnParentPath(consumer.return, renderLanes);
}

if (!forcePropagateEntireTree) {
// During lazy propagation, when we find a match, we can defer
Expand Down

0 comments on commit ed58992

Please sign in to comment.