Skip to content

Commit 45ed506

Browse files
author
Brian Vaughn
committed
Added new failing tests (pending a separate fix to React)
1 parent 0ef4bdb commit 45ed506

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,39 @@ describe('useMutableSource', () => {
809809
});
810810
});
811811

812+
it('should recover from a mutation during yield when other work is scheduled', () => {
813+
const source = createSource('one');
814+
const mutableSource = createMutableSource(source);
815+
816+
act(() => {
817+
// Start a render that uses the mutable source.
818+
ReactNoop.render(
819+
<>
820+
<Component
821+
label="a"
822+
getSnapshot={defaultGetSnapshot}
823+
mutableSource={mutableSource}
824+
subscribe={defaultSubscribe}
825+
/>
826+
<Component
827+
label="b"
828+
getSnapshot={defaultGetSnapshot}
829+
mutableSource={mutableSource}
830+
subscribe={defaultSubscribe}
831+
/>
832+
</>,
833+
);
834+
expect(Scheduler).toFlushAndYieldThrough(['a:one']);
835+
836+
// Mutate source
837+
source.value = 'two';
838+
839+
// Now render something different.
840+
ReactNoop.render(<div />);
841+
expect(Scheduler).toFlushAndYield([]);
842+
});
843+
});
844+
812845
it('should not throw if the new getSnapshot returns the same snapshot value', () => {
813846
const source = createSource('one');
814847
const mutableSource = createMutableSource(source);

0 commit comments

Comments
 (0)