GeezerVison is showing github.com — [SuspenseList] Store lastEffect before rendering (#17131) · react/react@4eeee35
File treeExpand file treeCollapse file tree Open diff view settings packages/react-reconciler/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberBeginWork.js +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2355,18 +2355,20 @@ function initSuspenseListRenderState( | 2355 | 2355 | tail: null | Fiber, | 2356 | 2356 | lastContentRow: null | Fiber, | 2357 | 2357 | tailMode: SuspenseListTailMode, | | 2358 | + lastEffectBeforeRendering: null | Fiber, | 2358 | 2359 | ): void { | 2359 | 2360 | let renderState: null | SuspenseListRenderState = | 2360 | 2361 | workInProgress.memoizedState; | 2361 | 2362 | if (renderState === null) { | 2362 | | - workInProgress.memoizedState = { | | 2363 | + workInProgress.memoizedState = ({ | 2363 | 2364 | isBackwards: isBackwards, | 2364 | 2365 | rendering: null, | 2365 | 2366 | last: lastContentRow, | 2366 | 2367 | tail: tail, | 2367 | 2368 | tailExpiration: 0, | 2368 | 2369 | tailMode: tailMode, | 2369 | | - }; | | 2370 | + lastEffect: lastEffectBeforeRendering, | | 2371 | + }: SuspenseListRenderState); | 2370 | 2372 | } else { | 2371 | 2373 | // We can reuse the existing object from previous renders. | 2372 | 2374 | renderState.isBackwards = isBackwards; | @@ -2375,6 +2377,7 @@ function initSuspenseListRenderState( | 2375 | 2377 | renderState.tail = tail; | 2376 | 2378 | renderState.tailExpiration = 0; | 2377 | 2379 | renderState.tailMode = tailMode; | | 2380 | + renderState.lastEffect = lastEffectBeforeRendering; | 2378 | 2381 | } | 2379 | 2382 | } | 2380 | 2383 |
| @@ -2456,6 +2459,7 @@ function updateSuspenseListComponent( | 2456 | 2459 | tail, | 2457 | 2460 | lastContentRow, | 2458 | 2461 | tailMode, | | 2462 | + workInProgress.lastEffect, | 2459 | 2463 | ); | 2460 | 2464 | break; | 2461 | 2465 | } | @@ -2487,6 +2491,7 @@ function updateSuspenseListComponent( | 2487 | 2491 | tail, | 2488 | 2492 | null, // last | 2489 | 2493 | tailMode, | | 2494 | + workInProgress.lastEffect, | 2490 | 2495 | ); | 2491 | 2496 | break; | 2492 | 2497 | } | @@ -2497,6 +2502,7 @@ function updateSuspenseListComponent( | 2497 | 2502 | null, // tail | 2498 | 2503 | null, // last | 2499 | 2504 | undefined, | | 2505 | + workInProgress.lastEffect, | 2500 | 2506 | ); | 2501 | 2507 | break; | 2502 | 2508 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/ReactFiberCompleteWork.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1053,7 +1053,10 @@ function completeWork( | 1053 | 1053 | // Rerender the whole list, but this time, we'll force fallbacks | 1054 | 1054 | // to stay in place. | 1055 | 1055 | // Reset the effect list before doing the second pass since that's now invalid. | 1056 | | - workInProgress.firstEffect = workInProgress.lastEffect = null; | | 1056 | + if (renderState.lastEffect === null) { | | 1057 | + workInProgress.firstEffect = null; | | 1058 | + } | | 1059 | + workInProgress.lastEffect = renderState.lastEffect; | 1057 | 1060 | // Reset the child fibers to their original state. | 1058 | 1061 | resetChildFibers(workInProgress, renderExpirationTime); | 1059 | 1062 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/react-reconciler/src/__tests__/ReactSuspenseList-test.internal.js +84Lines changed: 84 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -585,6 +585,90 @@ describe('ReactSuspenseList', () => { | 585 | 585 | ); | 586 | 586 | }); | 587 | 587 |
| | 588 | + it('displays all "together" during an update', async () => { | | 589 | + let A = createAsyncText('A'); | | 590 | + let B = createAsyncText('B'); | | 591 | + let C = createAsyncText('C'); | | 592 | + let D = createAsyncText('D'); | | 593 | + | | 594 | + function Foo({step}) { | | 595 | + return ( | | 596 | + <SuspenseList revealOrder="together"> | | 597 | + {step === 0 && ( | | 598 | + <Suspense fallback={<Text text="Loading A" />}> | | 599 | + <A /> | | 600 | + </Suspense> | | 601 | + )} | | 602 | + {step === 0 && ( | | 603 | + <Suspense fallback={<Text text="Loading B" />}> | | 604 | + <B /> | | 605 | + </Suspense> | | 606 | + )} | | 607 | + {step === 1 && ( | | 608 | + <Suspense fallback={<Text text="Loading C" />}> | | 609 | + <C /> | | 610 | + </Suspense> | | 611 | + )} | | 612 | + {step === 1 && ( | | 613 | + <Suspense fallback={<Text text="Loading D" />}> | | 614 | + <D /> | | 615 | + </Suspense> | | 616 | + )} | | 617 | + </SuspenseList> | | 618 | + ); | | 619 | + } | | 620 | + | | 621 | + // Mount | | 622 | + await A.resolve(); | | 623 | + ReactNoop.render(<Foo step={0} />); | | 624 | + expect(Scheduler).toFlushAndYield([ | | 625 | + 'A', | | 626 | + 'Suspend! [B]', | | 627 | + 'Loading B', | | 628 | + 'Loading A', | | 629 | + 'Loading B', | | 630 | + ]); | | 631 | + expect(ReactNoop).toMatchRenderedOutput( | | 632 | + <> | | 633 | + <span>Loading A</span> | | 634 | + <span>Loading B</span> | | 635 | + </>, | | 636 | + ); | | 637 | + await B.resolve(); | | 638 | + expect(Scheduler).toFlushAndYield(['A', 'B']); | | 639 | + expect(ReactNoop).toMatchRenderedOutput( | | 640 | + <> | | 641 | + <span>A</span> | | 642 | + <span>B</span> | | 643 | + </>, | | 644 | + ); | | 645 | + | | 646 | + // Update | | 647 | + await C.resolve(); | | 648 | + ReactNoop.render(<Foo step={1} />); | | 649 | + expect(Scheduler).toFlushAndYield([ | | 650 | + 'C', | | 651 | + 'Suspend! [D]', | | 652 | + 'Loading D', | | 653 | + 'Loading C', | | 654 | + 'Loading D', | | 655 | + ]); | | 656 | + expect(ReactNoop).toMatchRenderedOutput( | | 657 | + <> | | 658 | + <span>Loading C</span> | | 659 | + <span>Loading D</span> | | 660 | + </>, | | 661 | + ); | | 662 | + await D.resolve(); | | 663 | + expect(Scheduler).toFlushAndYield(['C', 'D']); | | 664 | + expect(ReactNoop).toMatchRenderedOutput( | | 665 | + <> | | 666 | + <span>C</span> | | 667 | + <span>D</span> | | 668 | + </>, | | 669 | + ); | | 670 | + }); | | 671 | + | 588 | 672 | it('avoided boundaries can be coordinate with SuspenseList', async () => { | 589 | 673 | let A = createAsyncText('A'); | 590 | 674 | let B = createAsyncText('B'); | |
|