GeezerVison is showing github.com — Regression test: SuspenseList causes lost unmount (#20433) · react/react@3f9205c
File tree
Expand file treeCollapse file tree
Open diff view settings
packages/react-reconciler/src/__tests__
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactHooksWithNoopRenderer-test.js +56Lines changed: 56 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3416,4 +3416,60 @@ describe('ReactHooksWithNoopRenderer', () => { |
3416 | 3416 | 'Unmount A', |
3417 | 3417 | ]); |
3418 | 3418 | }); |
| 3419 | + |
| 3420 | + // @gate experimental |
| 3421 | + it('regression: SuspenseList causes unmounts to be dropped on deletion', async () => { |
| 3422 | + const SuspenseList = React.unstable_SuspenseList; |
| 3423 | + |
| 3424 | + function Row({label}) { |
| 3425 | + useEffect(() => { |
| 3426 | + Scheduler.unstable_yieldValue('Mount ' + label); |
| 3427 | + return () => { |
| 3428 | + Scheduler.unstable_yieldValue('Unmount ' + label); |
| 3429 | + }; |
| 3430 | + }, [label]); |
| 3431 | + return ( |
| 3432 | + <Suspense fallback="Loading..."> |
| 3433 | + <AsyncText text={label} /> |
| 3434 | + </Suspense> |
| 3435 | + ); |
| 3436 | + } |
| 3437 | + |
| 3438 | + function App() { |
| 3439 | + return ( |
| 3440 | + <SuspenseList revealOrder="together"> |
| 3441 | + <Row label="A" /> |
| 3442 | + <Row label="B" /> |
| 3443 | + </SuspenseList> |
| 3444 | + ); |
| 3445 | + } |
| 3446 | + |
| 3447 | + const root = ReactNoop.createRoot(); |
| 3448 | + await ReactNoop.act(async () => { |
| 3449 | + root.render(<App />); |
| 3450 | + }); |
| 3451 | + expect(Scheduler).toHaveYielded([ |
| 3452 | + 'Suspend! [A]', |
| 3453 | + 'Suspend! [B]', |
| 3454 | + 'Mount A', |
| 3455 | + 'Mount B', |
| 3456 | + ]); |
| 3457 | + |
| 3458 | + await ReactNoop.act(async () => { |
| 3459 | + await resolveText('A'); |
| 3460 | + }); |
| 3461 | + expect(Scheduler).toHaveYielded([ |
| 3462 | + 'Promise resolved [A]', |
| 3463 | + 'A', |
| 3464 | + 'Suspend! [B]', |
| 3465 | + ]); |
| 3466 | + |
| 3467 | + await ReactNoop.act(async () => { |
| 3468 | + root.render(null); |
| 3469 | + }); |
| 3470 | + // In the regression, SuspenseList would cause the children to "forget" that |
| 3471 | + // it contains passive effects. Then when we deleted the tree, these unmount |
| 3472 | + // effects would not fire. |
| 3473 | + expect(Scheduler).toHaveYielded(['Unmount A', 'Unmount B']); |
| 3474 | + }); |
3419 | 3475 | }); |