Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[suspense][error handling] Add failing unit test #16800

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,39 @@ describe('ReactSuspenseWithNoopRenderer', () => {
expect(Scheduler).toFlushExpired(['Hi']);
});
}

it('handles errors in the return path of a component that suspends', async () => {
// Covers an edge case where an error is thrown inside the complete phase
// of a component that is in the return path of a component that suspends.
// The second error should also be handled (i.e. able to be captured by
// an error boundary.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// an error boundary.
// an error boundary.)

class ErrorBoundary extends React.Component {
state = {error: null};
static getDerivedStateFromError(error, errorInfo) {
return {error};
}
render() {
if (this.state.error) {
return `Caught an error: ${this.state.error.message}`;
}
return this.props.children;
}
}

ReactNoop.renderLegacySyncRoot(
<Suspense fallback="Loading...">
<ErrorBoundary>
<errorInCompletePhase>
<AsyncText ms={1000} text="Async" />
</errorInCompletePhase>
</ErrorBoundary>
</Suspense>,
);

expect(ReactNoop).toMatchRenderedOutput(
'Caught an error: Error in host config.',
);
});
});

it('does not call lifecycles of a suspended component', async () => {
Expand Down