mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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:
+1
-2
@@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user