Skip to content

Commit

Permalink
Remove errant return assignment (#14164)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite authored Nov 9, 2018
1 parent e58ecda commit 4b163fe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,44 @@ describe('ReactSuspense', () => {

root.update(null);
expect(root).toFlushWithoutYielding();
jest.advanceTimersByTime(1000);
});

it('#14162', () => {
const {lazy} = React;

function Hello() {
return <span>hello</span>;
}

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 (
<Suspense fallback={<span>loading...</span>}>
{this.state.render && <LazyHello />}
</Suspense>
);
}
}

const root = ReactTestRenderer.create(null);

root.update(<App name="world" />);
jest.advanceTimersByTime(1000);
});
});
Expand Down

0 comments on commit 4b163fe

Please # to comment.