diff --git a/packages/react-reconciler/src/ReactCapturedValue.js b/packages/react-reconciler/src/ReactCapturedValue.js index 5f7ca2fcc77e7..f09be0c813325 100644 --- a/packages/react-reconciler/src/ReactCapturedValue.js +++ b/packages/react-reconciler/src/ReactCapturedValue.js @@ -13,7 +13,7 @@ import {getStackAddendumByWorkInProgressFiber} from 'shared/ReactFiberComponentT export type CapturedValue = { value: T, - source: Fiber | null, + source: Fiber, stack: string | null, }; @@ -29,7 +29,7 @@ export type CapturedError = { export function createCapturedValue( value: T, - source: Fiber | null, + source: Fiber, ): CapturedValue { // If the value is an error, call this function immediately after it is thrown // so the stack is accurate. diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 720fb9ffe1fb7..84f2fdb239441 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -4,10 +4,11 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * + * @flow */ import type {ReactElement, Source} from 'shared/ReactElementType'; -import type {ReactPortal, RefObject} from 'shared/ReactTypes'; +import type {ReactFragment, ReactPortal, RefObject} from 'shared/ReactTypes'; import type {TypeOfWork} from 'shared/ReactTypeOfWork'; import type {TypeOfMode} from './ReactTypeOfMode'; import type {TypeOfSideEffect} from 'shared/ReactTypeOfSideEffect'; @@ -320,7 +321,7 @@ export function createWorkInProgress( return workInProgress; } -export function createHostRootFiber(isAsync): Fiber { +export function createHostRootFiber(isAsync: boolean): Fiber { const mode = isAsync ? AsyncMode | StrictMode : NoContext; return createFiber(HostRoot, null, null, mode); } diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.js b/packages/react-reconciler/src/ReactFiberCommitWork.js index f3184ced83c83..967d90a449c0a 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.js @@ -9,7 +9,7 @@ import type {HostConfig} from 'react-reconciler'; import type {Fiber} from './ReactFiber'; -import type {FiberRoot} from './ReactFiber'; +import type {FiberRoot} from './ReactFiberRoot'; import type {ExpirationTime} from './ReactFiberExpirationTime'; import type {CapturedValue, CapturedError} from './ReactCapturedValue'; @@ -65,7 +65,7 @@ export function logError(boundary: Fiber, errorInfo: CapturedValue) { } const capturedError: CapturedError = { - componentName: source !== null ? getComponentName(source) : null, + componentName: getComponentName(source), componentStack: stack !== null ? stack : '', error: errorInfo.value, errorBoundary: null, @@ -95,7 +95,7 @@ export function logError(boundary: Fiber, errorInfo: CapturedValue) { export default function( config: HostConfig, - captureError: (failedFiber: Fiber, error: mixed) => Fiber | null, + captureError: (failedFiber: Fiber, error: mixed) => void, scheduleWork: ( fiber: Fiber, startTime: ExpirationTime, diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js index 562039393da4d..97688243da1dc 100644 --- a/packages/react-reconciler/src/ReactFiberScheduler.js +++ b/packages/react-reconciler/src/ReactFiberScheduler.js @@ -321,10 +321,12 @@ export default function( } // Restore the original state of the work-in-progress - assignFiberPropertiesInDEV( - failedUnitOfWork, - stashedWorkInProgressProperties, - ); + if (stashedWorkInProgressProperties !== null) { + assignFiberPropertiesInDEV( + failedUnitOfWork, + stashedWorkInProgressProperties, + ); + } switch (failedUnitOfWork.tag) { case HostRoot: popHostContainer(failedUnitOfWork); @@ -1078,7 +1080,7 @@ export default function( } if (__DEV__ && replayFailedUnitOfWorkWithInvokeGuardedCallback) { - const failedUnitOfWork = nextUnitOfWork; + const failedUnitOfWork: Fiber = nextUnitOfWork; replayUnitOfWork(failedUnitOfWork, thrownValue, isAsync); } diff --git a/packages/react-reconciler/src/ReactStrictModeWarnings.js b/packages/react-reconciler/src/ReactStrictModeWarnings.js index 0f39b09371d28..2ac119782e764 100644 --- a/packages/react-reconciler/src/ReactStrictModeWarnings.js +++ b/packages/react-reconciler/src/ReactStrictModeWarnings.js @@ -107,7 +107,7 @@ if (__DEV__) { pendingUnsafeLifecycleWarnings = new Map(); }; - const getStrictRoot = (fiber: Fiber): Fiber => { + const getStrictRoot = (fiber: Fiber | null): Fiber | null => { let maybeStrictRoot = null; while (fiber !== null) { @@ -227,6 +227,10 @@ if (__DEV__) { ) => { const strictRoot = getStrictRoot(fiber); + if (strictRoot === null) { + return; + } + // Dedup strategy: Warn once per component. // This is difficult to track any other way since component names // are often vague and are likely to collide between 3rd party libraries.