Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove callbackId field from FiberRoot #19458

Merged
merged 1 commit into from Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-reconciler/src/ReactFiberRoot.new.js
Expand Up @@ -38,7 +38,6 @@ function FiberRootNode(containerInfo, tag, hydrate) {
this.pendingContext = null;
this.hydrate = hydrate;
this.callbackNode = null;
this.callbackId = NoLanes;
this.callbackPriority = NoLanePriority;
this.eventTimes = createLaneMap(NoLanes);
this.expirationTimes = createLaneMap(NoTimestamp);
Expand Down
1 change: 0 additions & 1 deletion packages/react-reconciler/src/ReactFiberRoot.old.js
Expand Up @@ -38,7 +38,6 @@ function FiberRootNode(containerInfo, tag, hydrate) {
this.pendingContext = null;
this.hydrate = hydrate;
this.callbackNode = null;
this.callbackId = NoLanes;
this.callbackPriority = NoLanePriority;
this.eventTimes = createLaneMap(NoLanes);
this.expirationTimes = createLaneMap(NoTimestamp);
Expand Down
33 changes: 13 additions & 20 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Expand Up @@ -677,10 +677,10 @@ function markUpdateLaneFromFiberToRoot(
}

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

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

// Determine the next lanes to work on, and their priority.
const newCallbackId = getNextLanes(
const nextLanes = getNextLanes(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the comment on line 681 (which references the expiration time) is out of date, should we update that as well?

root,
root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
);
// This returns the priority level computed during the `getNextLanes` call.
const newCallbackPriority = returnNextLanesPriority();

if (newCallbackId === NoLanes) {
if (nextLanes === NoLanes) {
// Special case: There's nothing to work on.
if (existingCallbackNode !== null) {
cancelCallback(existingCallbackNode);
root.callbackNode = null;
root.callbackPriority = NoLanePriority;
root.callbackId = NoLanes;
}
return;
}

// Check if there's an existing task. We may be able to reuse it.
const existingCallbackId = root.callbackId;
const existingCallbackPriority = root.callbackPriority;
if (existingCallbackId !== NoLanes) {
if (newCallbackId === existingCallbackId) {
// This task is already scheduled. Let's check its priority.
if (existingCallbackPriority === newCallbackPriority) {
// The priority hasn't changed. Exit.
return;
}
// The task ID is the same but the priority changed. Cancel the existing
// callback. We'll schedule a new one below.
if (existingCallbackNode !== null) {
const existingCallbackPriority = root.callbackPriority;
if (existingCallbackPriority === newCallbackPriority) {
// The priority hasn't changed. We can reuse the existing task. Exit.
return;
}
// The priority changed. Cancel the existing callback. We'll schedule a new
// one below.
cancelCallback(existingCallbackNode);
}

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

root.callbackId = newCallbackId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to update the root callbackId with the next lane, why don't we need to do anything with the next lane in the new version?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was only used by this function. Since we don't need it for the logic above anymore, we don't have to store it.

root.callbackPriority = newCallbackPriority;
root.callbackNode = newCallbackNode;
}
Expand Down Expand Up @@ -2041,7 +2035,6 @@ function commitRootImpl(root, renderPriorityLevel) {
// commitRoot never returns a continuation; it always finishes synchronously.
// So we can clear these now to allow a new callback to be scheduled.
root.callbackNode = null;
root.callbackId = NoLanes;

// Update the first and last pending times on this root. The new first
// pending time is whatever is left on the root fiber.
Expand Down
33 changes: 13 additions & 20 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Expand Up @@ -670,10 +670,10 @@ function markUpdateLaneFromFiberToRoot(
}

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

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

// Determine the next lanes to work on, and their priority.
const newCallbackId = getNextLanes(
const nextLanes = getNextLanes(
root,
root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
);
// This returns the priority level computed during the `getNextLanes` call.
const newCallbackPriority = returnNextLanesPriority();

if (newCallbackId === NoLanes) {
if (nextLanes === NoLanes) {
// Special case: There's nothing to work on.
if (existingCallbackNode !== null) {
cancelCallback(existingCallbackNode);
root.callbackNode = null;
root.callbackPriority = NoLanePriority;
root.callbackId = NoLanes;
}
return;
}

// Check if there's an existing task. We may be able to reuse it.
const existingCallbackId = root.callbackId;
const existingCallbackPriority = root.callbackPriority;
if (existingCallbackId !== NoLanes) {
if (newCallbackId === existingCallbackId) {
// This task is already scheduled. Let's check its priority.
if (existingCallbackPriority === newCallbackPriority) {
// The priority hasn't changed. Exit.
return;
}
// The task ID is the same but the priority changed. Cancel the existing
// callback. We'll schedule a new one below.
if (existingCallbackNode !== null) {
const existingCallbackPriority = root.callbackPriority;
if (existingCallbackPriority === newCallbackPriority) {
// The priority hasn't changed. We can reuse the existing task. Exit.
return;
}
// The priority changed. Cancel the existing callback. We'll schedule a new
// one below.
cancelCallback(existingCallbackNode);
}

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

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

// Update the first and last pending times on this root. The new first
// pending time is whatever is left on the root fiber.
Expand Down
8 changes: 3 additions & 5 deletions packages/react-reconciler/src/ReactInternalTypes.js
Expand Up @@ -205,17 +205,15 @@ type BaseFiberRootProperties = {|
pendingContext: Object | null,
// Determines if we should attempt to hydrate on the initial mount
+hydrate: boolean,
// Node returned by Scheduler.scheduleCallback
callbackNode: *,

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

// Represents the next task that the root should work on, or the current one
// if it's already working.
callbackId: Lanes,
// Node returned by Scheduler.scheduleCallback. Represents the next rendering
// task that the root will work on.
callbackNode: *,
callbackPriority: LanePriority,
eventTimes: LaneMap<number>,
expirationTimes: LaneMap<number>,
Expand Down