Skip to content

Commit 57c32b1

Browse files
author
Brian Vaughn
committed
Fixed high pri updates erasing pending lower pri subscription updates
1 parent 560acda commit 57c32b1

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,12 @@ function useMutableSourceImpl<S>(
900900
isSafeToReadFromSource =
901901
pendingExpirationTime === NoWork ||
902902
pendingExpirationTime >= expirationTime;
903+
904+
if (!isSafeToReadFromSource) {
905+
// Preserve the pending update if the current priority doesn't include it.
906+
currentlyRenderingFiber.expirationTime = pendingExpirationTime;
907+
markUnprocessedUpdateTime(pendingExpirationTime);
908+
}
903909
}
904910

905911
let prevMemoizedState = ((hook.memoizedState: any): ?MutableSourceState<S>);

packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.internal.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,6 @@ describe('ReactHooksWithNoopRenderer', () => {
20162016
() => Scheduler.unstable_yieldValue('Sync effect'),
20172017
);
20182018
expect(Scheduler).toFlushAndYield(['a:one', 'b:one', 'Sync effect']);
2019-
ReactNoop.flushPassiveEffects();
20202019

20212020
// Changing values should schedule an update with React.
20222021
// Start working on this update but don't finish it.
@@ -2036,9 +2035,7 @@ describe('ReactHooksWithNoopRenderer', () => {
20362035
});
20372036
expect(Scheduler).toHaveYielded(['a:one', 'b:one', 'Sync effect']);
20382037

2039-
// TODO (useMutableSource) Re-enable the assertion below; it fails now for reasons unknown.
2040-
// Once the update is processed, the new value should be used
2041-
// expect(Scheduler).toFlushAndYield(['a:two', 'b:two']);
2038+
expect(Scheduler).toFlushAndYield(['a:two', 'b:two']);
20422039
});
20432040

20442041
it('should read from source on newly mounted subtree if no pending updates are scheduled for source', () => {
@@ -2098,6 +2095,12 @@ describe('ReactHooksWithNoopRenderer', () => {
20982095
});
20992096
expect(Scheduler).toHaveYielded(['a:two', 'b:two', 'Sync effect']);
21002097
});
2098+
2099+
// TODO (useMutableSource) Test case for a scoped subscription,
2100+
// followed by a render that reads from a different part of the store,
2101+
// with a mutation between its first and second read,
2102+
// that isn't picked up on by the scoped subscription,
2103+
// to verify that we also use the version number to protect against this case.
21012104
});
21022105

21032106
describe('useCallback', () => {

0 commit comments

Comments
 (0)