From ca4a18232aec2721b279a999df38f60ee24021ec Mon Sep 17 00:00:00 2001 From: Sota <5866096+sota000@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:24:02 -0700 Subject: [PATCH] Show a soft error when a text string or number is supplied as a child to non text wrappers --- .../src/ReactFabricHostConfig.js | 11 +++++------ .../src/__tests__/ReactFabric-test.internal.js | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index 842a33291fb07..5f0d0853a5ef1 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -21,8 +21,6 @@ import type { import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; import {create, diff} from './ReactNativeAttributePayload'; -import invariant from 'shared/invariant'; - import {dispatchEvent} from './ReactFabricEventEmitter'; import { @@ -251,10 +249,11 @@ export function createTextInstance( hostContext: HostContext, internalInstanceHandle: Object, ): TextInstance { - invariant( - hostContext.isInAParentText, - 'Text strings must be rendered within a component.', - ); + if (__DEV__) { + if (!hostContext.isInAParentText) { + console.error('Text strings must be rendered within a component.'); + } + } const tag = nextReactTag; nextReactTag += 2; diff --git a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js index 6b776c085fd40..0a0afc4adc2f8 100644 --- a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js @@ -665,7 +665,7 @@ describe('ReactFabric', () => { }); }); - it('should throw for text not inside of a ancestor', () => { + it('should console error for text not inside of a ancestor', () => { const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({ validAttributes: {}, uiViewClassName: 'RCTScrollView', @@ -683,7 +683,7 @@ describe('ReactFabric', () => { act(() => { ReactFabric.render(this should warn, 11); }); - }).toThrow('Text strings must be rendered within a component.'); + }).toErrorDev(['Text strings must be rendered within a component.']); expect(() => { act(() => { @@ -694,7 +694,7 @@ describe('ReactFabric', () => { 11, ); }); - }).toThrow('Text strings must be rendered within a component.'); + }).toErrorDev(['Text strings must be rendered within a component.']); }); it('should not throw for text inside of an indirect ancestor', () => {