From 860a53443bb7db36344ea59e5b55db9c19a5b399 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Thu, 8 Nov 2018 18:13:42 -0800 Subject: [PATCH] Remove errant return assignment (#14164) Oopsie! This could have been avoided if our types were modeled correctly with Flow (using a disjoint union). Fuzz tester didn't catch it because it does not generate cases where a Suspense component mounts with no children. I'll update it. --- .../src/ReactFiberBeginWork.js | 3 +- .../__tests__/ReactSuspense-test.internal.js | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberBeginWork.js b/packages/react-reconciler/src/ReactFiberBeginWork.js index 902e424c3505b..73b723bf65458 100644 --- a/packages/react-reconciler/src/ReactFiberBeginWork.js +++ b/packages/react-reconciler/src/ReactFiberBeginWork.js @@ -1242,7 +1242,7 @@ function updateSuspenseComponent( } else { // The current tree has not already timed out. That means the primary // children are not wrapped in a fragment fiber. - const currentPrimaryChild: Fiber = (current.child: any); + const currentPrimaryChild = current.child; if (nextDidTimeout) { // Timed out. Wrap the children in a fragment fiber to keep them // separate from the fallback children. @@ -1256,7 +1256,6 @@ function updateSuspenseComponent( null, ); primaryChildFragment.child = currentPrimaryChild; - currentPrimaryChild.return = primaryChildFragment; // Even though we're creating a new fiber, there are no new children, // because we're reusing an already mounted tree. So we don't need to diff --git a/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js index 8647b2a5d5c61..5b4e111c169d0 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js @@ -883,7 +883,44 @@ describe('ReactSuspense', () => { root.update(null); expect(root).toFlushWithoutYielding(); + jest.advanceTimersByTime(1000); + }); + + it('#14162', () => { + const {lazy} = React; + + function Hello() { + return hello; + } + + async function fetchComponent() { + return new Promise(r => { + // simulating a delayed import() call + setTimeout(r, 1000, {default: Hello}); + }); + } + + const LazyHello = lazy(fetchComponent); + + class App extends React.Component { + state = {render: false}; + + componentDidMount() { + setTimeout(() => this.setState({render: true})); + } + + render() { + return ( + loading...}> + {this.state.render && } + + ); + } + } + + const root = ReactTestRenderer.create(null); + root.update(); jest.advanceTimersByTime(1000); }); });