Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ function updateSuspenseComponent(
));
fallbackChildFragment.effectTag |= Placement;
child = primaryChildFragment;
primaryChildFragment.childExpirationTime = NoWork;
// Skip the primary children, and continue working on the
// fallback children.
next = fallbackChildFragment;
Expand Down Expand Up @@ -1147,6 +1148,7 @@ function updateSuspenseComponent(
));
fallbackChildFragment.effectTag |= Placement;
child = primaryChildFragment;
primaryChildFragment.childExpirationTime = NoWork;
// Skip the primary children, and continue working on the
// fallback children.
next = fallbackChildFragment;
Expand Down Expand Up @@ -1464,6 +1466,7 @@ function beginWork(
const nextState = workInProgress.memoizedState;
const nextDidTimeout = nextState !== null && nextState.didTimeout;
if (nextDidTimeout) {
child.childExpirationTime = NoWork;
return child.sibling;
} else {
return child;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,5 +435,53 @@ describe('ReactSuspense', () => {
]);
expect(root).toMatchRenderedOutput('AB:2C');
});

it('bails out on timed-out primary children even if they receive an update', () => {
let instance;
class Stateful extends React.Component {
state = {step: 1};
render() {
instance = this;
return <Text text="Stateful" />;
}
}

function App(props) {
return (
<Suspense fallback={<Text text="Loading..." />}>
<Stateful />
<AsyncText ms={1000} text={props.text} />
</Suspense>
);
}

const root = ReactTestRenderer.create(<App text="A" />);

expect(ReactTestRenderer).toHaveYielded([
'Stateful',
'Suspend! [A]',
'Loading...',
]);

jest.advanceTimersByTime(1000);
expect(ReactTestRenderer).toHaveYielded(['Promise resolved [A]', 'A']);
expect(root).toMatchRenderedOutput('StatefulA');

root.update(<App text="B" />);
expect(ReactTestRenderer).toHaveYielded([
'Stateful',
'Suspend! [B]',
'Loading...',
]);

instance.setState({step: 2});

jest.advanceTimersByTime(1000);
expect(ReactTestRenderer).toHaveYielded([
'Promise resolved [B]',
'Stateful',
'B',
]);
});
});
});