From 4ee592e95a5f78daed575a047d47f74f046940f3 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 28 Feb 2020 11:56:36 +0000 Subject: [PATCH] Add an early invariant to debug a mystery crash (#18159) --- packages/react-reconciler/src/ReactFiber.js | 13 +++++++++++++ packages/shared/ReactFeatureFlags.js | 3 +++ .../shared/forks/ReactFeatureFlags.native-fb.js | 3 +++ .../shared/forks/ReactFeatureFlags.native-oss.js | 3 +++ .../shared/forks/ReactFeatureFlags.persistent.js | 3 +++ .../shared/forks/ReactFeatureFlags.test-renderer.js | 3 +++ .../forks/ReactFeatureFlags.test-renderer.www.js | 3 +++ packages/shared/forks/ReactFeatureFlags.testing.js | 3 +++ .../shared/forks/ReactFeatureFlags.testing.www.js | 3 +++ packages/shared/forks/ReactFeatureFlags.www.js | 3 +++ 10 files changed, 40 insertions(+) diff --git a/packages/react-reconciler/src/ReactFiber.js b/packages/react-reconciler/src/ReactFiber.js index 35a6c1e6e77a7..cec56e0860a6b 100644 --- a/packages/react-reconciler/src/ReactFiber.js +++ b/packages/react-reconciler/src/ReactFiber.js @@ -34,6 +34,7 @@ import { enableUserTimingAPI, enableScopeAPI, enableBlocksAPI, + throwEarlyForMysteriousError, } from 'shared/ReactFeatureFlags'; import {NoEffect, Placement} from 'shared/ReactSideEffectTags'; import {ConcurrentRoot, BlockingRoot} from 'shared/ReactRootTags'; @@ -453,6 +454,18 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber { } } + if (throwEarlyForMysteriousError) { + // Trying to debug a mysterious internal-only production failure. + // See D20130868 and t62461245. + // This is only on for RN FB builds. + if (current == null) { + throw Error('current is ' + current + " but it can't be"); + } + if (workInProgress == null) { + throw Error('workInProgress is ' + workInProgress + " but it can't be"); + } + } + workInProgress.childExpirationTime = current.childExpirationTime; workInProgress.expirationTime = current.expirationTime; diff --git a/packages/shared/ReactFeatureFlags.js b/packages/shared/ReactFeatureFlags.js index db731ebe97dd6..24d62ac2b06d7 100644 --- a/packages/shared/ReactFeatureFlags.js +++ b/packages/shared/ReactFeatureFlags.js @@ -105,6 +105,9 @@ export const deferPassiveEffectCleanupDuringUnmount = false; // a deprecated pattern we want to get rid of in the future export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // -------------------------- // Future APIs to be deprecated // -------------------------- diff --git a/packages/shared/forks/ReactFeatureFlags.native-fb.js b/packages/shared/forks/ReactFeatureFlags.native-fb.js index dd6c0fea3ee2c..5b50b15fc6700 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-fb.js +++ b/packages/shared/forks/ReactFeatureFlags.native-fb.js @@ -50,6 +50,9 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; export const enableModernEventSystem = false; export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = true; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.native-oss.js b/packages/shared/forks/ReactFeatureFlags.native-oss.js index e4754dbb00b95..2ef64264e4243 100644 --- a/packages/shared/forks/ReactFeatureFlags.native-oss.js +++ b/packages/shared/forks/ReactFeatureFlags.native-oss.js @@ -45,6 +45,9 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; export const enableModernEventSystem = false; export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.persistent.js b/packages/shared/forks/ReactFeatureFlags.persistent.js index 966f9ccc85c55..cd0a7955b0d6a 100644 --- a/packages/shared/forks/ReactFeatureFlags.persistent.js +++ b/packages/shared/forks/ReactFeatureFlags.persistent.js @@ -45,6 +45,9 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; export const enableModernEventSystem = false; export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.js index 0fb4a3652f756..61c5b861c11ef 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.js @@ -45,6 +45,9 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; export const enableModernEventSystem = false; export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js index e2b46797610fa..76a747ef7cc8f 100644 --- a/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js +++ b/packages/shared/forks/ReactFeatureFlags.test-renderer.www.js @@ -45,6 +45,9 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; export const enableModernEventSystem = false; export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.testing.js b/packages/shared/forks/ReactFeatureFlags.testing.js index 8040556c580b1..6dde781472ead 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.js @@ -45,6 +45,9 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; export const enableModernEventSystem = false; export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.testing.www.js b/packages/shared/forks/ReactFeatureFlags.testing.www.js index c47dd5705b61a..3a2fff266c2ab 100644 --- a/packages/shared/forks/ReactFeatureFlags.testing.www.js +++ b/packages/shared/forks/ReactFeatureFlags.testing.www.js @@ -45,6 +45,9 @@ export const runAllPassiveEffectDestroysBeforeCreates = false; export const enableModernEventSystem = false; export const warnAboutSpreadingKeyToJSX = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // Only used in www builds. export function addUserTimingListener() { invariant(false, 'Not implemented.'); diff --git a/packages/shared/forks/ReactFeatureFlags.www.js b/packages/shared/forks/ReactFeatureFlags.www.js index 2a45ce22eda95..d352e0b662247 100644 --- a/packages/shared/forks/ReactFeatureFlags.www.js +++ b/packages/shared/forks/ReactFeatureFlags.www.js @@ -99,6 +99,9 @@ export const warnUnstableRenderSubtreeIntoContainer = false; export const enableModernEventSystem = false; +// Internal-only attempt to debug a React Native issue. See D20130868. +export const throwEarlyForMysteriousError = false; + // Flow magic to verify the exports of this file match the original version. // eslint-disable-next-line no-unused-vars type Check<_X, Y: _X, X: Y = _X> = null;