From e176a6b5baa08745d2e8f29468a391c7adb236a5 Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Wed, 29 May 2019 19:59:02 -0700 Subject: [PATCH] Add test that we don't restart for initial render --- ...tSuspenseWithNoopRenderer-test.internal.js | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js index 1f0fbd6f6bf5d..a42136a80b90f 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js @@ -108,6 +108,70 @@ describe('ReactSuspenseWithNoopRenderer', () => { ]); }); + it('does not restart rendering for initial render', async () => { + function Bar(props) { + Scheduler.yieldValue('Bar'); + return props.children; + } + + function Foo() { + Scheduler.yieldValue('Foo'); + return ( + + }> + + + + + + + + + ); + } + + ReactNoop.render(); + expect(Scheduler).toFlushAndYieldThrough([ + 'Foo', + 'Bar', + // A suspends + 'Suspend! [A]', + // But we keep rendering the siblings + 'B', + 'Loading...', + 'C', + // We leave D incomplete. + ]); + expect(ReactNoop.getChildren()).toEqual([]); + + // Flush the promise completely + Scheduler.advanceTime(100); + await advanceTimers(100); + expect(Scheduler).toHaveYielded(['Promise resolved [A]']); + + // Even though the promise has resolved, we should now flush + // and commit the in progress render instead of restarting. + expect(Scheduler).toFlushAndYield(['D']); + expect(ReactNoop.getChildren()).toEqual([ + span('Loading...'), + span('C'), + span('D'), + ]); + + // Await one micro task to attach the retry listeners. + await null; + + // Next, we'll flush the complete content. + expect(Scheduler).toFlushAndYield(['Bar', 'A', 'B']); + + expect(ReactNoop.getChildren()).toEqual([ + span('A'), + span('B'), + span('C'), + span('D'), + ]); + }); + it('suspends rendering and continues later', async () => { function Bar(props) { Scheduler.yieldValue('Bar');