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.
This commit is contained in:
Andrew Clark
2018-11-08 18:13:42 -08:00
committed by GitHub
parent e58ecda9a2
commit 4b163fee1c
2 changed files with 38 additions and 2 deletions
+1 -2
View File
@@ -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
@@ -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);
});
});