Skip to content

Commit e020ac5

Browse files
acdlitejetoneza
authored andcommitted
Remove errant return assignment (facebook#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.
1 parent 8ba5ed7 commit e020ac5

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ function updateSuspenseComponent(
12421242
} else {
12431243
// The current tree has not already timed out. That means the primary
12441244
// children are not wrapped in a fragment fiber.
1245-
const currentPrimaryChild: Fiber = (current.child: any);
1245+
const currentPrimaryChild = current.child;
12461246
if (nextDidTimeout) {
12471247
// Timed out. Wrap the children in a fragment fiber to keep them
12481248
// separate from the fallback children.
@@ -1256,7 +1256,6 @@ function updateSuspenseComponent(
12561256
null,
12571257
);
12581258
primaryChildFragment.child = currentPrimaryChild;
1259-
currentPrimaryChild.return = primaryChildFragment;
12601259

12611260
// Even though we're creating a new fiber, there are no new children,
12621261
// because we're reusing an already mounted tree. So we don't need to

packages/react-reconciler/src/__tests__/ReactSuspense-test.internal.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,44 @@ describe('ReactSuspense', () => {
883883

884884
root.update(null);
885885
expect(root).toFlushWithoutYielding();
886+
jest.advanceTimersByTime(1000);
887+
});
888+
889+
it('#14162', () => {
890+
const {lazy} = React;
891+
892+
function Hello() {
893+
return <span>hello</span>;
894+
}
895+
896+
async function fetchComponent() {
897+
return new Promise(r => {
898+
// simulating a delayed import() call
899+
setTimeout(r, 1000, {default: Hello});
900+
});
901+
}
902+
903+
const LazyHello = lazy(fetchComponent);
904+
905+
class App extends React.Component {
906+
state = {render: false};
907+
908+
componentDidMount() {
909+
setTimeout(() => this.setState({render: true}));
910+
}
911+
912+
render() {
913+
return (
914+
<Suspense fallback={<span>loading...</span>}>
915+
{this.state.render && <LazyHello />}
916+
</Suspense>
917+
);
918+
}
919+
}
920+
921+
const root = ReactTestRenderer.create(null);
886922

923+
root.update(<App name="world" />);
887924
jest.advanceTimersByTime(1000);
888925
});
889926
});

0 commit comments

Comments
 (0)