Skip to content

Commit

Permalink
Swapped first/last logic in setPendingExpirationTime and removed no l…
Browse files Browse the repository at this point in the history
…onger in use "first" time value
  • Loading branch information
Brian Vaughn committed Apr 3, 2020
1 parent 1a73af5 commit db511f4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
8 changes: 4 additions & 4 deletions packages/react-reconciler/src/ReactFiberHooks.js
Expand Up @@ -75,7 +75,7 @@ import {
getCurrentPriorityLevel,
} from './SchedulerWithReactIntegration';
import {
getFirstPendingExpirationTime,
getLastPendingExpirationTime,
getWorkInProgressVersion,
markSourceAsDirty,
setPendingExpirationTime,
Expand Down Expand Up @@ -916,7 +916,7 @@ function readFromUnsubcribedMutableSource<Source, Snapshot>(
isSafeToReadFromSource = currentRenderVersion === version;
} else {
// If there's no version, then we should fallback to checking the update time.
const pendingExpirationTime = getFirstPendingExpirationTime(root);
const pendingExpirationTime = getLastPendingExpirationTime(root);

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

Expand Down
1 change: 0 additions & 1 deletion packages/react-reconciler/src/ReactFiberRoot.js
Expand Up @@ -79,7 +79,6 @@ type BaseFiberRootProperties = {|
lastExpiredTime: ExpirationTime,
// Used by useMutableSource hook to avoid tearing within this root
// when external, mutable sources are read from during render.
mutableSourceFirstPendingUpdateTime: ExpirationTime,
mutableSourceLastPendingUpdateTime: ExpirationTime,
|};

Expand Down
25 changes: 6 additions & 19 deletions packages/react-reconciler/src/ReactMutableSource.js
Expand Up @@ -32,19 +32,10 @@ export function clearPendingUpdates(
): void {
if (expirationTime <= root.mutableSourceLastPendingUpdateTime) {
// All updates for this source have been processed.
root.mutableSourceFirstPendingUpdateTime = NoWork;
root.mutableSourceLastPendingUpdateTime = NoWork;
} else if (expirationTime <= root.mutableSourceFirstPendingUpdateTime) {
// The highest priority pending updates have been processed,
// but we don't how many updates remain between the current and lowest priority.
root.mutableSourceFirstPendingUpdateTime = expirationTime - 1;
}
}

export function getFirstPendingExpirationTime(root: FiberRoot): ExpirationTime {
return root.mutableSourceFirstPendingUpdateTime;
}

export function getLastPendingExpirationTime(root: FiberRoot): ExpirationTime {
return root.mutableSourceLastPendingUpdateTime;
}
Expand All @@ -53,18 +44,14 @@ export function setPendingExpirationTime(
root: FiberRoot,
expirationTime: ExpirationTime,
): void {
// Because we only track one pending update time per root,
// track the lowest priority update.
// It's inclusive of all other pending updates.
if (expirationTime > root.mutableSourceLastPendingUpdateTime) {
const mutableSourceLastPendingUpdateTime =
root.mutableSourceLastPendingUpdateTime;
if (
mutableSourceLastPendingUpdateTime === NoWork ||
expirationTime < mutableSourceLastPendingUpdateTime
) {
root.mutableSourceLastPendingUpdateTime = expirationTime;
}

if (root.mutableSourceFirstPendingUpdateTime === NoWork) {
root.mutableSourceFirstPendingUpdateTime = expirationTime;
} else if (expirationTime < root.mutableSourceFirstPendingUpdateTime) {
root.mutableSourceFirstPendingUpdateTime = expirationTime;
}
}

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

0 comments on commit db511f4

Please sign in to comment.