Skip to content

Commit f519354

Browse files
committed
Remove errant return assignment
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 f9e9913 commit f519354

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ function updateSuspenseComponent(
12441244
} else {
12451245
// The current tree has not already timed out. That means the primary
12461246
// children are not wrapped in a fragment fiber.
1247-
const currentPrimaryChild: Fiber = (current.child: any);
1247+
const currentPrimaryChild: Fiber | null = (current.child: any);
12481248
if (nextDidTimeout) {
12491249
// Timed out. Wrap the children in a fragment fiber to keep them
12501250
// separate from the fallback children.
@@ -1260,7 +1260,6 @@ function updateSuspenseComponent(
12601260

12611261
primaryChildFragment.effectTag |= Placement;
12621262
primaryChildFragment.child = currentPrimaryChild;
1263-
currentPrimaryChild.return = primaryChildFragment;
12641263

12651264
if ((workInProgress.mode & ConcurrentMode) === NoContext) {
12661265
// Outside of concurrent mode, we commit the effects from the

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,5 +838,43 @@ describe('ReactSuspense', () => {
838838
]);
839839
expect(root).toMatchRenderedOutput('Tab: 2 + sibling');
840840
});
841+
842+
it('#14162', () => {
843+
const {lazy} = React;
844+
845+
function Hello() {
846+
return <span>hello</span>;
847+
}
848+
849+
async function fetchComponent() {
850+
return new Promise(r => {
851+
// simulating a delayed import() call
852+
setTimeout(r, 1000, {default: Hello});
853+
});
854+
}
855+
856+
const LazyHello = lazy(fetchComponent);
857+
858+
class App extends React.Component {
859+
state = {render: false};
860+
861+
componentDidMount() {
862+
setTimeout(() => this.setState({render: true}));
863+
}
864+
865+
render() {
866+
return (
867+
<Suspense fallback={<span>loading...</span>}>
868+
{this.state.render && <LazyHello />}
869+
</Suspense>
870+
);
871+
}
872+
}
873+
874+
const root = ReactTestRenderer.create(null);
875+
876+
root.update(<App name="world" />);
877+
jest.advanceTimersByTime(1000);
878+
});
841879
});
842880
});

0 commit comments

Comments
 (0)