Skip to content

Commit 180f0dd

Browse files
gaearonacdlite
authored andcommitted
Add failing test for stuck Suspense fallback
1 parent f444c28 commit 180f0dd

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,5 +690,33 @@ describe('ReactSuspense', () => {
690690
);
691691
expect(mounts).toBe(1);
692692
});
693+
694+
it('does not get stuck with fallback in concurrent mode for a large delay', () => {
695+
function App(props) {
696+
return (
697+
<Suspense maxDuration={10} fallback={<Text text="Loading..." />}>
698+
<AsyncText ms={1000} text="Child 1" />
699+
<AsyncText ms={7000} text="Child 2" />
700+
</Suspense>
701+
);
702+
}
703+
704+
const root = ReactTestRenderer.create(<App />, {
705+
unstable_isConcurrent: true,
706+
});
707+
708+
expect(root).toFlushAndYield([
709+
'Suspend! [Child 1]',
710+
'Suspend! [Child 2]',
711+
'Loading...',
712+
]);
713+
jest.advanceTimersByTime(1000);
714+
expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Child 1]']);
715+
expect(root).toFlushAndYield(['Child 1', 'Suspend! [Child 2]']);
716+
jest.advanceTimersByTime(6000);
717+
expect(ReactTestRenderer).toHaveYielded(['Promise resolved [Child 2]']);
718+
expect(root).toFlushAndYield(['Child 1', 'Child 2']);
719+
expect(root).toMatchRenderedOutput(['Child 1', 'Child 2'].join(''));
720+
});
693721
});
694722
});

0 commit comments

Comments
 (0)