Skip to content

Commit 96ac799

Browse files
authored
Remove callbackId field from FiberRoot (facebook#19458)
The old expiration times implementation used this field to infer when the priority of a task had changed at a more granular level than a Scheduler priority level. Now that we have the LanePriority type, which is React-specific, we no longer need the `callbackId` field.
1 parent c24b641 commit 96ac799

File tree

5 files changed

+29
-47
lines changed

5 files changed

+29
-47
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function FiberRootNode(containerInfo, tag, hydrate) {
3838
this.pendingContext = null;
3939
this.hydrate = hydrate;
4040
this.callbackNode = null;
41-
this.callbackId = NoLanes;
4241
this.callbackPriority = NoLanePriority;
4342
this.eventTimes = createLaneMap(NoLanes);
4443
this.expirationTimes = createLaneMap(NoTimestamp);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ function FiberRootNode(containerInfo, tag, hydrate) {
3838
this.pendingContext = null;
3939
this.hydrate = hydrate;
4040
this.callbackNode = null;
41-
this.callbackId = NoLanes;
4241
this.callbackPriority = NoLanePriority;
4342
this.eventTimes = createLaneMap(NoLanes);
4443
this.expirationTimes = createLaneMap(NoTimestamp);

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,10 @@ function markUpdateLaneFromFiberToRoot(
677677
}
678678

679679
// Use this function to schedule a task for a root. There's only one task per
680-
// root; if a task was already scheduled, we'll check to make sure the
681-
// expiration time of the existing task is the same as the expiration time of
682-
// the next level that the root has work on. This function is called on every
683-
// update, and right before exiting a task.
680+
// root; if a task was already scheduled, we'll check to make sure the priority
681+
// of the existing task is the same as the priority of the next level that the
682+
// root has work on. This function is called on every update, and right before
683+
// exiting a task.
684684
function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
685685
const existingCallbackNode = root.callbackNode;
686686

@@ -689,37 +689,32 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
689689
markStarvedLanesAsExpired(root, currentTime);
690690

691691
// Determine the next lanes to work on, and their priority.
692-
const newCallbackId = getNextLanes(
692+
const nextLanes = getNextLanes(
693693
root,
694694
root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
695695
);
696696
// This returns the priority level computed during the `getNextLanes` call.
697697
const newCallbackPriority = returnNextLanesPriority();
698698

699-
if (newCallbackId === NoLanes) {
699+
if (nextLanes === NoLanes) {
700700
// Special case: There's nothing to work on.
701701
if (existingCallbackNode !== null) {
702702
cancelCallback(existingCallbackNode);
703703
root.callbackNode = null;
704704
root.callbackPriority = NoLanePriority;
705-
root.callbackId = NoLanes;
706705
}
707706
return;
708707
}
709708

710709
// Check if there's an existing task. We may be able to reuse it.
711-
const existingCallbackId = root.callbackId;
712-
const existingCallbackPriority = root.callbackPriority;
713-
if (existingCallbackId !== NoLanes) {
714-
if (newCallbackId === existingCallbackId) {
715-
// This task is already scheduled. Let's check its priority.
716-
if (existingCallbackPriority === newCallbackPriority) {
717-
// The priority hasn't changed. Exit.
718-
return;
719-
}
720-
// The task ID is the same but the priority changed. Cancel the existing
721-
// callback. We'll schedule a new one below.
710+
if (existingCallbackNode !== null) {
711+
const existingCallbackPriority = root.callbackPriority;
712+
if (existingCallbackPriority === newCallbackPriority) {
713+
// The priority hasn't changed. We can reuse the existing task. Exit.
714+
return;
722715
}
716+
// The priority changed. Cancel the existing callback. We'll schedule a new
717+
// one below.
723718
cancelCallback(existingCallbackNode);
724719
}
725720

@@ -741,7 +736,6 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
741736
);
742737
}
743738

744-
root.callbackId = newCallbackId;
745739
root.callbackPriority = newCallbackPriority;
746740
root.callbackNode = newCallbackNode;
747741
}
@@ -2041,7 +2035,6 @@ function commitRootImpl(root, renderPriorityLevel) {
20412035
// commitRoot never returns a continuation; it always finishes synchronously.
20422036
// So we can clear these now to allow a new callback to be scheduled.
20432037
root.callbackNode = null;
2044-
root.callbackId = NoLanes;
20452038

20462039
// Update the first and last pending times on this root. The new first
20472040
// pending time is whatever is left on the root fiber.

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

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,10 @@ function markUpdateLaneFromFiberToRoot(
670670
}
671671

672672
// Use this function to schedule a task for a root. There's only one task per
673-
// root; if a task was already scheduled, we'll check to make sure the
674-
// expiration time of the existing task is the same as the expiration time of
675-
// the next level that the root has work on. This function is called on every
676-
// update, and right before exiting a task.
673+
// root; if a task was already scheduled, we'll check to make sure the priority
674+
// of the existing task is the same as the priority of the next level that the
675+
// root has work on. This function is called on every update, and right before
676+
// exiting a task.
677677
function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
678678
const existingCallbackNode = root.callbackNode;
679679

@@ -682,37 +682,32 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
682682
markStarvedLanesAsExpired(root, currentTime);
683683

684684
// Determine the next lanes to work on, and their priority.
685-
const newCallbackId = getNextLanes(
685+
const nextLanes = getNextLanes(
686686
root,
687687
root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
688688
);
689689
// This returns the priority level computed during the `getNextLanes` call.
690690
const newCallbackPriority = returnNextLanesPriority();
691691

692-
if (newCallbackId === NoLanes) {
692+
if (nextLanes === NoLanes) {
693693
// Special case: There's nothing to work on.
694694
if (existingCallbackNode !== null) {
695695
cancelCallback(existingCallbackNode);
696696
root.callbackNode = null;
697697
root.callbackPriority = NoLanePriority;
698-
root.callbackId = NoLanes;
699698
}
700699
return;
701700
}
702701

703702
// Check if there's an existing task. We may be able to reuse it.
704-
const existingCallbackId = root.callbackId;
705-
const existingCallbackPriority = root.callbackPriority;
706-
if (existingCallbackId !== NoLanes) {
707-
if (newCallbackId === existingCallbackId) {
708-
// This task is already scheduled. Let's check its priority.
709-
if (existingCallbackPriority === newCallbackPriority) {
710-
// The priority hasn't changed. Exit.
711-
return;
712-
}
713-
// The task ID is the same but the priority changed. Cancel the existing
714-
// callback. We'll schedule a new one below.
703+
if (existingCallbackNode !== null) {
704+
const existingCallbackPriority = root.callbackPriority;
705+
if (existingCallbackPriority === newCallbackPriority) {
706+
// The priority hasn't changed. We can reuse the existing task. Exit.
707+
return;
715708
}
709+
// The priority changed. Cancel the existing callback. We'll schedule a new
710+
// one below.
716711
cancelCallback(existingCallbackNode);
717712
}
718713

@@ -734,7 +729,6 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
734729
);
735730
}
736731

737-
root.callbackId = newCallbackId;
738732
root.callbackPriority = newCallbackPriority;
739733
root.callbackNode = newCallbackNode;
740734
}
@@ -1959,7 +1953,6 @@ function commitRootImpl(root, renderPriorityLevel) {
19591953
// commitRoot never returns a continuation; it always finishes synchronously.
19601954
// So we can clear these now to allow a new callback to be scheduled.
19611955
root.callbackNode = null;
1962-
root.callbackId = NoLanes;
19631956

19641957
// Update the first and last pending times on this root. The new first
19651958
// pending time is whatever is left on the root fiber.

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,15 @@ type BaseFiberRootProperties = {|
205205
pendingContext: Object | null,
206206
// Determines if we should attempt to hydrate on the initial mount
207207
+hydrate: boolean,
208-
// Node returned by Scheduler.scheduleCallback
209-
callbackNode: *,
210208

211209
// Used by useMutableSource hook to avoid tearing during hydration.
212210
mutableSourceEagerHydrationData?: Array<
213211
MutableSource<any> | MutableSourceVersion,
214212
> | null,
215213

216-
// Represents the next task that the root should work on, or the current one
217-
// if it's already working.
218-
callbackId: Lanes,
214+
// Node returned by Scheduler.scheduleCallback. Represents the next rendering
215+
// task that the root will work on.
216+
callbackNode: *,
219217
callbackPriority: LanePriority,
220218
eventTimes: LaneMap<number>,
221219
expirationTimes: LaneMap<number>,

0 commit comments

Comments
 (0)