Skip to content

Commit db511f4

Browse files
author
Brian Vaughn
committed
Swapped first/last logic in setPendingExpirationTime and removed no longer in use "first" time value
1 parent 1a73af5 commit db511f4

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

packages/react-reconciler/src/ReactFiberHooks.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import {
7575
getCurrentPriorityLevel,
7676
} from './SchedulerWithReactIntegration';
7777
import {
78-
getFirstPendingExpirationTime,
78+
getLastPendingExpirationTime,
7979
getWorkInProgressVersion,
8080
markSourceAsDirty,
8181
setPendingExpirationTime,
@@ -916,7 +916,7 @@ function readFromUnsubcribedMutableSource<Source, Snapshot>(
916916
isSafeToReadFromSource = currentRenderVersion === version;
917917
} else {
918918
// If there's no version, then we should fallback to checking the update time.
919-
const pendingExpirationTime = getFirstPendingExpirationTime(root);
919+
const pendingExpirationTime = getLastPendingExpirationTime(root);
920920

921921
if (pendingExpirationTime === NoWork) {
922922
isSafeToReadFromSource = true;
@@ -1040,7 +1040,7 @@ function useMutableSource<Source, Snapshot>(
10401040
// There is no mechanism currently to associate these updates though,
10411041
// so for now we fall back to synchronously flushing all pending updates.
10421042
// TODO: Improve this later.
1043-
markRootExpiredAtTime(root, getFirstPendingExpirationTime(root));
1043+
markRootExpiredAtTime(root, getLastPendingExpirationTime(root));
10441044
}
10451045
}
10461046
}
@@ -1108,7 +1108,7 @@ function useMutableSource<Source, Snapshot>(
11081108
// We missed a mutation before committing.
11091109
// It's possible that other components using this source also have pending updates scheduled.
11101110
// In that case, we should ensure they all commit together.
1111-
markRootExpiredAtTime(root, getFirstPendingExpirationTime(root));
1111+
markRootExpiredAtTime(root, getLastPendingExpirationTime(root));
11121112
}
11131113
}
11141114

packages/react-reconciler/src/ReactFiberRoot.js

-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ type BaseFiberRootProperties = {|
7979
lastExpiredTime: ExpirationTime,
8080
// Used by useMutableSource hook to avoid tearing within this root
8181
// when external, mutable sources are read from during render.
82-
mutableSourceFirstPendingUpdateTime: ExpirationTime,
8382
mutableSourceLastPendingUpdateTime: ExpirationTime,
8483
|};
8584

packages/react-reconciler/src/ReactMutableSource.js

+6-19
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,10 @@ export function clearPendingUpdates(
3232
): void {
3333
if (expirationTime <= root.mutableSourceLastPendingUpdateTime) {
3434
// All updates for this source have been processed.
35-
root.mutableSourceFirstPendingUpdateTime = NoWork;
3635
root.mutableSourceLastPendingUpdateTime = NoWork;
37-
} else if (expirationTime <= root.mutableSourceFirstPendingUpdateTime) {
38-
// The highest priority pending updates have been processed,
39-
// but we don't how many updates remain between the current and lowest priority.
40-
root.mutableSourceFirstPendingUpdateTime = expirationTime - 1;
4136
}
4237
}
4338

44-
export function getFirstPendingExpirationTime(root: FiberRoot): ExpirationTime {
45-
return root.mutableSourceFirstPendingUpdateTime;
46-
}
47-
4839
export function getLastPendingExpirationTime(root: FiberRoot): ExpirationTime {
4940
return root.mutableSourceLastPendingUpdateTime;
5041
}
@@ -53,18 +44,14 @@ export function setPendingExpirationTime(
5344
root: FiberRoot,
5445
expirationTime: ExpirationTime,
5546
): void {
56-
// Because we only track one pending update time per root,
57-
// track the lowest priority update.
58-
// It's inclusive of all other pending updates.
59-
if (expirationTime > root.mutableSourceLastPendingUpdateTime) {
47+
const mutableSourceLastPendingUpdateTime =
48+
root.mutableSourceLastPendingUpdateTime;
49+
if (
50+
mutableSourceLastPendingUpdateTime === NoWork ||
51+
expirationTime < mutableSourceLastPendingUpdateTime
52+
) {
6053
root.mutableSourceLastPendingUpdateTime = expirationTime;
6154
}
62-
63-
if (root.mutableSourceFirstPendingUpdateTime === NoWork) {
64-
root.mutableSourceFirstPendingUpdateTime = expirationTime;
65-
} else if (expirationTime < root.mutableSourceFirstPendingUpdateTime) {
66-
root.mutableSourceFirstPendingUpdateTime = expirationTime;
67-
}
6855
}
6956

7057
export function markSourceAsDirty(mutableSource: MutableSource<any>): void {

0 commit comments

Comments
 (0)