diff --git a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js index 97f0f480fbeba..c7b2629be7327 100644 --- a/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js +++ b/packages/react-reconciler/src/__tests__/ReactSuspenseWithNoopRenderer-test.internal.js @@ -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. + 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( + + + + + + + , + ); + + expect(ReactNoop).toMatchRenderedOutput( + 'Caught an error: Error in host config.', + ); + }); }); it('does not call lifecycles of a suspended component', async () => {