Skip to content

Commit b7a0583

Browse files
committed
Failing test for #18657
1 parent a4b1e65 commit b7a0583

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js

+49
Original file line numberDiff line numberDiff line change
@@ -3869,4 +3869,53 @@ describe('ReactSuspenseWithNoopRenderer', () => {
38693869
expect(root).toMatchRenderedOutput(<span prop="b" />);
38703870
});
38713871
});
3872+
3873+
it('regression: #18657', async () => {
3874+
const {useState} = React;
3875+
3876+
let setText;
3877+
function App() {
3878+
const [text, _setText] = useState('A');
3879+
setText = _setText;
3880+
return <AsyncText text={text} />;
3881+
}
3882+
3883+
const root = ReactNoop.createRoot();
3884+
await ReactNoop.act(async () => {
3885+
await resolveText('A');
3886+
root.render(
3887+
<Suspense fallback={<Text text="Loading..." />}>
3888+
<App />
3889+
</Suspense>,
3890+
);
3891+
});
3892+
expect(Scheduler).toHaveYielded(['A']);
3893+
expect(root).toMatchRenderedOutput(<span prop="A" />);
3894+
3895+
await ReactNoop.act(async () => {
3896+
setText('B');
3897+
Scheduler.unstable_runWithPriority(
3898+
Scheduler.unstable_IdlePriority,
3899+
() => {
3900+
setText('B');
3901+
},
3902+
);
3903+
// Suspend the first update. The second update doesn't run because it has
3904+
// Idle priority.
3905+
expect(Scheduler).toFlushAndYield(['Suspend! [B]', 'Loading...']);
3906+
3907+
// Commit the fallback. Now we'll try working on Idle.
3908+
jest.runAllTimers();
3909+
3910+
// It also suspends.
3911+
expect(Scheduler).toFlushAndYield(['Suspend! [B]']);
3912+
});
3913+
3914+
await ReactNoop.act(async () => {
3915+
setText('B');
3916+
await resolveText('B');
3917+
});
3918+
expect(Scheduler).toHaveYielded(['Promise resolved [B]', 'B']);
3919+
expect(root).toMatchRenderedOutput(<span prop="B" />);
3920+
});
38723921
});

0 commit comments

Comments
 (0)