diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index c74e8cacb2..2e0037fb7f 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -1183,6 +1183,7 @@ src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js * recovers from uncaught reconciler errors * unmounts components with uncaught errors * does not interrupt unmounting if detaching a ref throws +* handles error thrown by host config while working on failed root src/renderers/shared/fiber/__tests__/ReactIncrementalReflection-test.js * handles isMounted even when the initial render is deferred diff --git a/src/renderers/noop/ReactNoop.js b/src/renderers/noop/ReactNoop.js index 6dde764abd..df866a8907 100644 --- a/src/renderers/noop/ReactNoop.js +++ b/src/renderers/noop/ReactNoop.js @@ -39,9 +39,14 @@ type TextInstance = {| text: string, id: number |}; var instanceCounter = 0; +var failInBeginPhase = false; + var NoopRenderer = ReactFiberReconciler({ getRootHostContext() { + if (failInBeginPhase) { + throw new Error('Error in host config.'); + } return emptyObject; }, @@ -353,6 +358,15 @@ var ReactNoop = { console.log(...bufferedLog); }, + simulateErrorInHostConfig(fn : () => void) { + failInBeginPhase = true; + try { + fn(); + } finally { + failInBeginPhase = false; + } + }, + }; module.exports = ReactNoop; diff --git a/src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js b/src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js index 94a163a80d..bdca15e7cd 100644 --- a/src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js +++ b/src/renderers/shared/fiber/__tests__/ReactIncrementalErrorHandling-test.js @@ -917,4 +917,11 @@ describe('ReactIncrementalErrorHandling', () => { // Because there was an error, entire tree should unmount expect(ReactNoop.getChildren()).toEqual([]); }); + + it('handles error thrown by host config while working on failed root', () => { + ReactNoop.simulateErrorInHostConfig(() => { + ReactNoop.render(); + expect(() => ReactNoop.flush()).toThrow('Error in host config.'); + }); + }); });