Skip to content

Commit

Permalink
Address nits
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jan 18, 2022
1 parent 0ce097b commit 92c5c04
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 26 deletions.
10 changes: 5 additions & 5 deletions packages/react-reconciler/src/ReactFiberBeginWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ import {
checkIfContextChanged,
readContext,
prepareToReadContext,
scheduleWorkOnParentPath,
scheduleContextWorkOnParentPath,
} from './ReactFiberNewContext.new';
import {
renderWithHooks,
Expand Down Expand Up @@ -2754,13 +2754,13 @@ function updateDehydratedSuspenseComponent(
}
}

function scheduleWorkOnFiber(fiber: Fiber, renderLanes: Lanes) {
function scheduleContextWorkOnFiber(fiber: Fiber, renderLanes: Lanes) {
fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
const alternate = fiber.alternate;
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(fiber.return, renderLanes, null);
scheduleContextWorkOnParentPath(fiber.return, renderLanes, null);
}

function propagateSuspenseContextChange(
Expand All @@ -2776,15 +2776,15 @@ function propagateSuspenseContextChange(
if (node.tag === SuspenseComponent) {
const state: SuspenseState | null = node.memoizedState;
if (state !== null) {
scheduleWorkOnFiber(node, renderLanes);
scheduleContextWorkOnFiber(node, renderLanes);
}
} else if (node.tag === SuspenseListComponent) {
// If the tail is hidden there might not be an Suspense boundaries
// to schedule work on. In this case we have to schedule it on the
// list itself.
// We don't have to traverse to the children of the list since
// the list will propagate the change when it rerenders.
scheduleWorkOnFiber(node, renderLanes);
scheduleContextWorkOnFiber(node, renderLanes);
} else if (node.child !== null) {
node.child.return = node;
node = node.child;
Expand Down
10 changes: 5 additions & 5 deletions packages/react-reconciler/src/ReactFiberBeginWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ import {
checkIfContextChanged,
readContext,
prepareToReadContext,
scheduleWorkOnParentPath,
scheduleContextWorkOnParentPath,
} from './ReactFiberNewContext.old';
import {
renderWithHooks,
Expand Down Expand Up @@ -2754,13 +2754,13 @@ function updateDehydratedSuspenseComponent(
}
}

function scheduleWorkOnFiber(fiber: Fiber, renderLanes: Lanes) {
function scheduleContextWorkOnFiber(fiber: Fiber, renderLanes: Lanes) {
fiber.lanes = mergeLanes(fiber.lanes, renderLanes);
const alternate = fiber.alternate;
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(fiber.return, renderLanes, null);
scheduleContextWorkOnParentPath(fiber.return, renderLanes, null);
}

function propagateSuspenseContextChange(
Expand All @@ -2776,15 +2776,15 @@ function propagateSuspenseContextChange(
if (node.tag === SuspenseComponent) {
const state: SuspenseState | null = node.memoizedState;
if (state !== null) {
scheduleWorkOnFiber(node, renderLanes);
scheduleContextWorkOnFiber(node, renderLanes);
}
} else if (node.tag === SuspenseListComponent) {
// If the tail is hidden there might not be an Suspense boundaries
// to schedule work on. In this case we have to schedule it on the
// list itself.
// We don't have to traverse to the children of the list since
// the list will propagate the change when it rerenders.
scheduleWorkOnFiber(node, renderLanes);
scheduleContextWorkOnFiber(node, renderLanes);
} else if (node.child !== null) {
node.child.return = node;
node = node.child;
Expand Down
35 changes: 27 additions & 8 deletions packages/react-reconciler/src/ReactFiberNewContext.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,13 @@ export function popProvider(
}
}

export function scheduleWorkOnParentPath(
export function scheduleContextWorkOnParentPath(
parent: Fiber | null,
renderLanes: Lanes,
stopAt: Fiber | null,
propagationRoot: Fiber | null,
) {
// Update the child lanes of all the ancestors, including the alternates.
let node = parent;
const stopAtAlternate = stopAt !== null ? stopAt.alternate : null;
while (node !== null) {
const alternate = node.alternate;
if (!isSubsetOfLanes(node.childLanes, renderLanes)) {
Expand All @@ -166,9 +165,17 @@ export function scheduleWorkOnParentPath(
// or fallback trees because childLanes may be inconsistent
// with the surroundings. This is why we continue the loop.
}
if (node === stopAt || node === stopAtAlternate) {
if (node === propagationRoot) {
break;
}
if (__DEV__) {
if (propagationRoot !== null && node === propagationRoot.alternate) {
console.error(
'Did not expect to encounter a propagation root alternate when scheduling context work. ' +
'This error is likely caused by a bug in React. Please file an issue.',
);
}
}
node = node.return;
}
}
Expand Down Expand Up @@ -254,7 +261,11 @@ function propagateContextChange_eager<T>(
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(fiber.return, renderLanes, workInProgress);
scheduleContextWorkOnParentPath(
fiber.return,
renderLanes,
workInProgress,
);

// Mark the updated lanes on the list, too.
list.lanes = mergeLanes(list.lanes, renderLanes);
Expand Down Expand Up @@ -292,7 +303,11 @@ function propagateContextChange_eager<T>(
// 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.
scheduleWorkOnParentPath(parentSuspense, renderLanes, workInProgress);
scheduleContextWorkOnParentPath(
parentSuspense,
renderLanes,
workInProgress,
);
nextFiber = fiber.sibling;
} else {
// Traverse down.
Expand Down Expand Up @@ -373,7 +388,7 @@ function propagateContextChanges<T>(
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(
scheduleContextWorkOnParentPath(
consumer.return,
renderLanes,
workInProgress,
Expand Down Expand Up @@ -418,7 +433,11 @@ function propagateContextChanges<T>(
// 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.
scheduleWorkOnParentPath(parentSuspense, renderLanes, workInProgress);
scheduleContextWorkOnParentPath(
parentSuspense,
renderLanes,
workInProgress,
);
nextFiber = null;
} else {
// Traverse down.
Expand Down
35 changes: 27 additions & 8 deletions packages/react-reconciler/src/ReactFiberNewContext.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,13 @@ export function popProvider(
}
}

export function scheduleWorkOnParentPath(
export function scheduleContextWorkOnParentPath(
parent: Fiber | null,
renderLanes: Lanes,
stopAt: Fiber | null,
propagationRoot: Fiber | null,
) {
// Update the child lanes of all the ancestors, including the alternates.
let node = parent;
const stopAtAlternate = stopAt !== null ? stopAt.alternate : null;
while (node !== null) {
const alternate = node.alternate;
if (!isSubsetOfLanes(node.childLanes, renderLanes)) {
Expand All @@ -166,9 +165,17 @@ export function scheduleWorkOnParentPath(
// or fallback trees because childLanes may be inconsistent
// with the surroundings. This is why we continue the loop.
}
if (node === stopAt || node === stopAtAlternate) {
if (node === propagationRoot) {
break;
}
if (__DEV__) {
if (propagationRoot !== null && node === propagationRoot.alternate) {
console.error(
'Did not expect to encounter a propagation root alternate when scheduling context work. ' +
'This error is likely caused by a bug in React. Please file an issue.',
);
}
}
node = node.return;
}
}
Expand Down Expand Up @@ -254,7 +261,11 @@ function propagateContextChange_eager<T>(
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(fiber.return, renderLanes, workInProgress);
scheduleContextWorkOnParentPath(
fiber.return,
renderLanes,
workInProgress,
);

// Mark the updated lanes on the list, too.
list.lanes = mergeLanes(list.lanes, renderLanes);
Expand Down Expand Up @@ -292,7 +303,11 @@ function propagateContextChange_eager<T>(
// 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.
scheduleWorkOnParentPath(parentSuspense, renderLanes, workInProgress);
scheduleContextWorkOnParentPath(
parentSuspense,
renderLanes,
workInProgress,
);
nextFiber = fiber.sibling;
} else {
// Traverse down.
Expand Down Expand Up @@ -373,7 +388,7 @@ function propagateContextChanges<T>(
if (alternate !== null) {
alternate.lanes = mergeLanes(alternate.lanes, renderLanes);
}
scheduleWorkOnParentPath(
scheduleContextWorkOnParentPath(
consumer.return,
renderLanes,
workInProgress,
Expand Down Expand Up @@ -418,7 +433,11 @@ function propagateContextChanges<T>(
// 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.
scheduleWorkOnParentPath(parentSuspense, renderLanes, workInProgress);
scheduleContextWorkOnParentPath(
parentSuspense,
renderLanes,
workInProgress,
);
nextFiber = null;
} else {
// Traverse down.
Expand Down

0 comments on commit 92c5c04

Please sign in to comment.