From fab3639ca9ade3cf748002e59e5b4694ecbabd3a Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Mon, 31 Aug 2020 12:38:52 -0500 Subject: [PATCH 1/2] Bug: Effect clean up when deleting suspended tree Adds a failing unit test. --- .../ReactSuspenseWithNoopRenderer-test.js | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js index c10772eaa16e5..48d25ecd9aa5f 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.js @@ -3956,4 +3956,53 @@ describe('ReactSuspenseWithNoopRenderer', () => { , ); }); + + it('should fire effect clean-up when deleting suspended tree', async () => { + const {useEffect} = React; + + function App({show}) { + return ( + }> + + {show && } + + ); + } + + function Child() { + useEffect(() => { + Scheduler.unstable_yieldValue('Mount Child'); + return () => { + Scheduler.unstable_yieldValue('Unmount Child'); + }; + }, []); + return ; + } + + const root = ReactNoop.createRoot(); + + await ReactNoop.act(async () => { + root.render(); + }); + expect(Scheduler).toHaveYielded(['Mount Child']); + expect(root).toMatchRenderedOutput(); + + await ReactNoop.act(async () => { + root.render(); + }); + // TODO: `act` should have flushed the placeholder + jest.runAllTimers(); + expect(Scheduler).toHaveYielded(['Suspend! [Async]', 'Loading...']); + expect(root).toMatchRenderedOutput( + <> +