Skip to content

Commit 5fa8e68

Browse files
committed
New test: retry after error during expired render
1 parent fc79757 commit 5fa8e68

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,55 @@ describe('ReactIncrementalErrorHandling', () => {
381381
expect(ReactNoop.getChildren()).toEqual([]);
382382
});
383383

384+
it('retries one more time if an error occurs during a render that expires midway through the tree', () => {
385+
function Oops() {
386+
Scheduler.unstable_yieldValue('Oops');
387+
throw new Error('Oops');
388+
}
389+
390+
function Text({text}) {
391+
Scheduler.unstable_yieldValue(text);
392+
return text;
393+
}
394+
395+
function App() {
396+
return (
397+
<>
398+
<Text text="A" />
399+
<Text text="B" />
400+
<Oops />
401+
<Text text="C" />
402+
<Text text="D" />
403+
</>
404+
);
405+
}
406+
407+
ReactNoop.render(<App />);
408+
409+
// Render part of the tree
410+
expect(Scheduler).toFlushAndYieldThrough(['A', 'B']);
411+
412+
// Expire the render midway through
413+
expect(() => ReactNoop.expire(10000)).toThrow('Oops');
414+
415+
expect(Scheduler).toHaveYielded([
416+
// The render expired, but we shouldn't throw out the partial work.
417+
// Finish the current level.
418+
'Oops',
419+
'C',
420+
'D',
421+
422+
// Since the error occured during a partially concurrent render, we should
423+
// retry one more time, synchonrously.
424+
'A',
425+
'B',
426+
'Oops',
427+
'C',
428+
'D',
429+
]);
430+
expect(ReactNoop.getChildren()).toEqual([]);
431+
});
432+
384433
it('calls componentDidCatch multiple times for multiple errors', () => {
385434
let id = 0;
386435
class BadMount extends React.Component {

0 commit comments

Comments
 (0)