Compare commits

...

2 Commits

Author SHA1 Message Date
Sebastian Silbermann
78c05c7368 Gate and assert non-tearing 2024-03-01 15:18:03 +01:00
Brian Vaughn
92f17ebdd2 Add failing test for issue #27670 2023-11-08 20:41:10 -05:00
2 changed files with 12560 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -294,4 +294,61 @@ describe('useSyncExternalStore', () => {
);
},
);
// @gate enableActivity
test('detecting mutation in previously hidden activity subtree', async () => {
const store = createExternalStore('revision:1');
function App({mode, revision}) {
return (
<React.unstable_Activity mode={mode}>
<Wrapper revision={revision}>
<Subscriber />
</Wrapper>
</React.unstable_Activity>
);
}
function Wrapper({children, revision}) {
useLayoutEffect(() => {
store.set('revision:' + revision);
}, [revision]);
return (
<>
wrapper:{revision}
{', '}
{children}
</>
);
}
function Subscriber() {
const revision = useSyncExternalStore(store.subscribe, store.getState);
return <Text text={revision} />;
}
const root = ReactNoop.createRoot();
// Mount app
await act(() => {
root.render(<App mode="visible" revision="1" />);
});
assertLog(['revision:1']);
expect(root).toMatchRenderedOutput('wrapper:1, revision:1');
// Hide subtree
await act(() => {
root.render(<App mode="hidden" revision="1" />);
});
assertLog(['revision:1']);
expect(root).toMatchRenderedOutput('');
// Show subtree (and update mutable store in a layout effect)
await act(() => {
root.render(<App mode="visible" revision="2" />);
});
assertLog(['revision:1', 'revision:2']);
expect(root).toMatchRenderedOutput('wrapper:2, revision:2');
});
});