Skip to content

Commit

Permalink
Remove errant return assignment
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 committed Nov 9, 2018
1 parent 7fd1661 commit 355c0be
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 @@ -1244,7 +1244,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 @@ -1260,7 +1260,6 @@ function updateSuspenseComponent(

primaryChildFragment.effectTag |= Placement;
primaryChildFragment.child = currentPrimaryChild;
currentPrimaryChild.return = primaryChildFragment;

if ((workInProgress.mode & ConcurrentMode) === NoContext) {
// Outside of concurrent mode, we commit the effects from the
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 355c0be

Please sign in to comment.