Skip to content

Commit 99f7728

Browse files
committed
Pass event time to markRootUpdated
Some minor rearranging so that eventTime gets threaded through. No change in behavior.
1 parent faa697f commit 99f7728

3 files changed

Lines changed: 113 additions & 115 deletions

File tree

packages/react-reconciler/src/ReactFiberLane.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,11 @@ export function createLaneMap<T>(initial: T): LaneMap<T> {
648648
return new Array(TotalLanes).fill(initial);
649649
}
650650

651-
export function markRootUpdated(root: FiberRoot, updateLane: Lane) {
651+
export function markRootUpdated(
652+
root: FiberRoot,
653+
updateLane: Lane,
654+
eventTime: number,
655+
) {
652656
root.pendingLanes |= updateLane;
653657

654658
// TODO: Theoretically, any update to any lane can unblock any other lane. But

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

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,35 @@ export function scheduleUpdateOnFiber(
540540
return null;
541541
}
542542

543+
// Mark that the root has a pending update.
544+
markRootUpdated(root, lane, eventTime);
545+
546+
if (root === workInProgressRoot) {
547+
// Received an update to a tree that's in the middle of rendering. Mark
548+
// that there was an interleaved update work on this root. Unless the
549+
// `deferRenderPhaseUpdateToNextBatch` flag is off and this is a render
550+
// phase update. In that case, we don't treat render phase updates as if
551+
// they were interleaved, for backwards compat reasons.
552+
if (
553+
deferRenderPhaseUpdateToNextBatch ||
554+
(executionContext & RenderContext) === NoContext
555+
) {
556+
workInProgressRootUpdatedLanes = mergeLanes(
557+
workInProgressRootUpdatedLanes,
558+
lane,
559+
);
560+
}
561+
if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
562+
// The root already suspended with a delay, which means this render
563+
// definitely won't finish. Since we have a new update, let's mark it as
564+
// suspended now, right before marking the incoming update. This has the
565+
// effect of interrupting the current render and switching to the update.
566+
// TODO: Make sure this doesn't override pings that happen while we've
567+
// already started rendering.
568+
markRootSuspended(root, workInProgressRootRenderLanes);
569+
}
570+
}
571+
543572
// TODO: requestUpdateLanePriority also reads the priority. Pass the
544573
// priority as an argument to that function and this one.
545574
const priorityLevel = getCurrentPriorityLevel();
@@ -605,82 +634,47 @@ export function scheduleUpdateOnFiber(
605634
// e.g. retrying a Suspense boundary isn't an update, but it does schedule work
606635
// on a fiber.
607636
function markUpdateLaneFromFiberToRoot(
608-
fiber: Fiber,
637+
sourceFiber: Fiber,
609638
lane: Lane,
610639
): FiberRoot | null {
611640
// Update the source fiber's lanes
612-
fiber.lanes = mergeLanes(fiber.lanes, lane);
613-
let alternate = fiber.alternate;
641+
sourceFiber.lanes = mergeLanes(sourceFiber.lanes, lane);
642+
let alternate = sourceFiber.alternate;
614643
if (alternate !== null) {
615644
alternate.lanes = mergeLanes(alternate.lanes, lane);
616645
}
617646
if (__DEV__) {
618647
if (
619648
alternate === null &&
620-
(fiber.effectTag & (Placement | Hydrating)) !== NoEffect
649+
(sourceFiber.effectTag & (Placement | Hydrating)) !== NoEffect
621650
) {
622-
warnAboutUpdateOnNotYetMountedFiberInDEV(fiber);
651+
warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
623652
}
624653
}
625654
// Walk the parent path to the root and update the child expiration time.
626-
let node = fiber.return;
627-
let root = null;
628-
if (node === null && fiber.tag === HostRoot) {
629-
root = fiber.stateNode;
630-
} else {
631-
while (node !== null) {
632-
alternate = node.alternate;
655+
let node = sourceFiber;
656+
let parent = sourceFiber.return;
657+
while (parent !== null) {
658+
parent.childLanes = mergeLanes(parent.childLanes, lane);
659+
alternate = parent.alternate;
660+
if (alternate !== null) {
661+
alternate.childLanes = mergeLanes(alternate.childLanes, lane);
662+
} else {
633663
if (__DEV__) {
634-
if (
635-
alternate === null &&
636-
(node.effectTag & (Placement | Hydrating)) !== NoEffect
637-
) {
638-
warnAboutUpdateOnNotYetMountedFiberInDEV(fiber);
664+
if ((parent.effectTag & (Placement | Hydrating)) !== NoEffect) {
665+
warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
639666
}
640667
}
641-
node.childLanes = mergeLanes(node.childLanes, lane);
642-
if (alternate !== null) {
643-
alternate.childLanes = mergeLanes(alternate.childLanes, lane);
644-
}
645-
if (node.return === null && node.tag === HostRoot) {
646-
root = node.stateNode;
647-
break;
648-
}
649-
node = node.return;
650668
}
669+
node = parent;
670+
parent = parent.return;
651671
}
652-
653-
if (root !== null) {
654-
// Mark that the root has a pending update.
655-
markRootUpdated(root, lane);
656-
if (workInProgressRoot === root) {
657-
// Received an update to a tree that's in the middle of rendering. Mark
658-
// that there was an interleaved update work on this root. Unless the
659-
// `deferRenderPhaseUpdateToNextBatch` flag is off and this is a render
660-
// phase update. In that case, we don't treat render phase updates as if
661-
// they were interleaved, for backwards compat reasons.
662-
if (
663-
deferRenderPhaseUpdateToNextBatch ||
664-
(executionContext & RenderContext) === NoContext
665-
) {
666-
workInProgressRootUpdatedLanes = mergeLanes(
667-
workInProgressRootUpdatedLanes,
668-
lane,
669-
);
670-
}
671-
if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
672-
// The root already suspended with a delay, which means this render
673-
// definitely won't finish. Since we have a new update, let's mark it as
674-
// suspended now, right before marking the incoming update. This has the
675-
// effect of interrupting the current render and switching to the update.
676-
// TODO: Make sure this doesn't override pings that happen while we've
677-
// already started rendering.
678-
markRootSuspended(root, workInProgressRootRenderLanes);
679-
}
680-
}
672+
if (node.tag === HostRoot) {
673+
const root: FiberRoot = node.stateNode;
674+
return root;
675+
} else {
676+
return null;
681677
}
682-
683-
return root;
684678
}
685679

686680
// Use this function to schedule a task for a root. There's only one task per
@@ -2908,6 +2902,7 @@ function captureCommitPhaseErrorOnRoot(
29082902
const eventTime = requestEventTime();
29092903
const root = markUpdateLaneFromFiberToRoot(rootFiber, (SyncLane: Lane));
29102904
if (root !== null) {
2905+
markRootUpdated(root, SyncLane, eventTime);
29112906
ensureRootIsScheduled(root, eventTime);
29122907
schedulePendingInteractions(root, SyncLane);
29132908
}
@@ -2944,6 +2939,7 @@ export function captureCommitPhaseError(sourceFiber: Fiber, error: mixed) {
29442939
const eventTime = requestEventTime();
29452940
const root = markUpdateLaneFromFiberToRoot(fiber, (SyncLane: Lane));
29462941
if (root !== null) {
2942+
markRootUpdated(root, SyncLane, eventTime);
29472943
ensureRootIsScheduled(root, eventTime);
29482944
schedulePendingInteractions(root, SyncLane);
29492945
}
@@ -3016,6 +3012,7 @@ function retryTimedOutBoundary(boundaryFiber: Fiber, retryLane: Lane) {
30163012
const eventTime = requestEventTime();
30173013
const root = markUpdateLaneFromFiberToRoot(boundaryFiber, retryLane);
30183014
if (root !== null) {
3015+
markRootUpdated(root, retryLane, eventTime);
30193016
ensureRootIsScheduled(root, eventTime);
30203017
schedulePendingInteractions(root, retryLane);
30213018
}

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

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,35 @@ export function scheduleUpdateOnFiber(
533533
return null;
534534
}
535535

536+
// Mark that the root has a pending update.
537+
markRootUpdated(root, lane, eventTime);
538+
539+
if (root === workInProgressRoot) {
540+
// Received an update to a tree that's in the middle of rendering. Mark
541+
// that there was an interleaved update work on this root. Unless the
542+
// `deferRenderPhaseUpdateToNextBatch` flag is off and this is a render
543+
// phase update. In that case, we don't treat render phase updates as if
544+
// they were interleaved, for backwards compat reasons.
545+
if (
546+
deferRenderPhaseUpdateToNextBatch ||
547+
(executionContext & RenderContext) === NoContext
548+
) {
549+
workInProgressRootUpdatedLanes = mergeLanes(
550+
workInProgressRootUpdatedLanes,
551+
lane,
552+
);
553+
}
554+
if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
555+
// The root already suspended with a delay, which means this render
556+
// definitely won't finish. Since we have a new update, let's mark it as
557+
// suspended now, right before marking the incoming update. This has the
558+
// effect of interrupting the current render and switching to the update.
559+
// TODO: Make sure this doesn't override pings that happen while we've
560+
// already started rendering.
561+
markRootSuspended(root, workInProgressRootRenderLanes);
562+
}
563+
}
564+
536565
// TODO: requestUpdateLanePriority also reads the priority. Pass the
537566
// priority as an argument to that function and this one.
538567
const priorityLevel = getCurrentPriorityLevel();
@@ -598,82 +627,47 @@ export function scheduleUpdateOnFiber(
598627
// e.g. retrying a Suspense boundary isn't an update, but it does schedule work
599628
// on a fiber.
600629
function markUpdateLaneFromFiberToRoot(
601-
fiber: Fiber,
630+
sourceFiber: Fiber,
602631
lane: Lane,
603632
): FiberRoot | null {
604633
// Update the source fiber's lanes
605-
fiber.lanes = mergeLanes(fiber.lanes, lane);
606-
let alternate = fiber.alternate;
634+
sourceFiber.lanes = mergeLanes(sourceFiber.lanes, lane);
635+
let alternate = sourceFiber.alternate;
607636
if (alternate !== null) {
608637
alternate.lanes = mergeLanes(alternate.lanes, lane);
609638
}
610639
if (__DEV__) {
611640
if (
612641
alternate === null &&
613-
(fiber.effectTag & (Placement | Hydrating)) !== NoEffect
642+
(sourceFiber.effectTag & (Placement | Hydrating)) !== NoEffect
614643
) {
615-
warnAboutUpdateOnNotYetMountedFiberInDEV(fiber);
644+
warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
616645
}
617646
}
618647
// Walk the parent path to the root and update the child expiration time.
619-
let node = fiber.return;
620-
let root = null;
621-
if (node === null && fiber.tag === HostRoot) {
622-
root = fiber.stateNode;
623-
} else {
624-
while (node !== null) {
625-
alternate = node.alternate;
648+
let node = sourceFiber;
649+
let parent = sourceFiber.return;
650+
while (parent !== null) {
651+
parent.childLanes = mergeLanes(parent.childLanes, lane);
652+
alternate = parent.alternate;
653+
if (alternate !== null) {
654+
alternate.childLanes = mergeLanes(alternate.childLanes, lane);
655+
} else {
626656
if (__DEV__) {
627-
if (
628-
alternate === null &&
629-
(node.effectTag & (Placement | Hydrating)) !== NoEffect
630-
) {
631-
warnAboutUpdateOnNotYetMountedFiberInDEV(fiber);
657+
if ((parent.effectTag & (Placement | Hydrating)) !== NoEffect) {
658+
warnAboutUpdateOnNotYetMountedFiberInDEV(sourceFiber);
632659
}
633660
}
634-
node.childLanes = mergeLanes(node.childLanes, lane);
635-
if (alternate !== null) {
636-
alternate.childLanes = mergeLanes(alternate.childLanes, lane);
637-
}
638-
if (node.return === null && node.tag === HostRoot) {
639-
root = node.stateNode;
640-
break;
641-
}
642-
node = node.return;
643661
}
662+
node = parent;
663+
parent = parent.return;
644664
}
645-
646-
if (root !== null) {
647-
// Mark that the root has a pending update.
648-
markRootUpdated(root, lane);
649-
if (workInProgressRoot === root) {
650-
// Received an update to a tree that's in the middle of rendering. Mark
651-
// that there was an interleaved update work on this root. Unless the
652-
// `deferRenderPhaseUpdateToNextBatch` flag is off and this is a render
653-
// phase update. In that case, we don't treat render phase updates as if
654-
// they were interleaved, for backwards compat reasons.
655-
if (
656-
deferRenderPhaseUpdateToNextBatch ||
657-
(executionContext & RenderContext) === NoContext
658-
) {
659-
workInProgressRootUpdatedLanes = mergeLanes(
660-
workInProgressRootUpdatedLanes,
661-
lane,
662-
);
663-
}
664-
if (workInProgressRootExitStatus === RootSuspendedWithDelay) {
665-
// The root already suspended with a delay, which means this render
666-
// definitely won't finish. Since we have a new update, let's mark it as
667-
// suspended now, right before marking the incoming update. This has the
668-
// effect of interrupting the current render and switching to the update.
669-
// TODO: Make sure this doesn't override pings that happen while we've
670-
// already started rendering.
671-
markRootSuspended(root, workInProgressRootRenderLanes);
672-
}
673-
}
665+
if (node.tag === HostRoot) {
666+
const root: FiberRoot = node.stateNode;
667+
return root;
668+
} else {
669+
return null;
674670
}
675-
676-
return root;
677671
}
678672

679673
// Use this function to schedule a task for a root. There's only one task per
@@ -2764,6 +2758,7 @@ function captureCommitPhaseErrorOnRoot(
27642758
const eventTime = requestEventTime();
27652759
const root = markUpdateLaneFromFiberToRoot(rootFiber, (SyncLane: Lane));
27662760
if (root !== null) {
2761+
markRootUpdated(root, SyncLane, eventTime);
27672762
ensureRootIsScheduled(root, eventTime);
27682763
schedulePendingInteractions(root, SyncLane);
27692764
}
@@ -2800,6 +2795,7 @@ export function captureCommitPhaseError(sourceFiber: Fiber, error: mixed) {
28002795
const eventTime = requestEventTime();
28012796
const root = markUpdateLaneFromFiberToRoot(fiber, (SyncLane: Lane));
28022797
if (root !== null) {
2798+
markRootUpdated(root, SyncLane, eventTime);
28032799
ensureRootIsScheduled(root, eventTime);
28042800
schedulePendingInteractions(root, SyncLane);
28052801
}
@@ -2872,6 +2868,7 @@ function retryTimedOutBoundary(boundaryFiber: Fiber, retryLane: Lane) {
28722868
const eventTime = requestEventTime();
28732869
const root = markUpdateLaneFromFiberToRoot(boundaryFiber, retryLane);
28742870
if (root !== null) {
2871+
markRootUpdated(root, retryLane, eventTime);
28752872
ensureRootIsScheduled(root, eventTime);
28762873
schedulePendingInteractions(root, retryLane);
28772874
}

0 commit comments

Comments
 (0)