From 424fe587087d05302259d6d5ebb359675387f3b1 Mon Sep 17 00:00:00 2001 From: Sota <5866096+sota000@users.noreply.github.com> Date: Mon, 16 Aug 2021 17:53:23 -0700 Subject: [PATCH] Revert "Show a soft error when a text string or number is supplied as a child to non text wrappers (#21953)" (#22108) This reverts commit e9b2028b3280c15138bd92b0d27ffa066de3d5ca. --- .../src/ReactFabricHostConfig.js | 11 ++++++----- .../src/ReactNativeHostConfig.js | 10 +++++----- .../src/__tests__/ReactFabric-test.internal.js | 6 +++--- .../src/__tests__/ReactNativeMount-test.internal.js | 10 +++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/react-native-renderer/src/ReactFabricHostConfig.js b/packages/react-native-renderer/src/ReactFabricHostConfig.js index c71a9050211c..8ca9401597dd 100644 --- a/packages/react-native-renderer/src/ReactFabricHostConfig.js +++ b/packages/react-native-renderer/src/ReactFabricHostConfig.js @@ -22,6 +22,8 @@ import type { import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; import {create, diff} from './ReactNativeAttributePayload'; +import invariant from 'shared/invariant'; + import {dispatchEvent} from './ReactFabricEventEmitter'; import { @@ -262,11 +264,10 @@ export function createTextInstance( hostContext: HostContext, internalInstanceHandle: Object, ): TextInstance { - if (__DEV__) { - if (!hostContext.isInAParentText) { - console.error('Text strings must be rendered within a component.'); - } - } + invariant( + hostContext.isInAParentText, + 'Text strings must be rendered within a component.', + ); const tag = nextReactTag; nextReactTag += 2; diff --git a/packages/react-native-renderer/src/ReactNativeHostConfig.js b/packages/react-native-renderer/src/ReactNativeHostConfig.js index 63337a04df1a..205f8189b7a7 100644 --- a/packages/react-native-renderer/src/ReactNativeHostConfig.js +++ b/packages/react-native-renderer/src/ReactNativeHostConfig.js @@ -147,11 +147,11 @@ export function createTextInstance( hostContext: HostContext, internalInstanceHandle: Object, ): TextInstance { - if (__DEV__) { - if (!hostContext.isInAParentText) { - console.error('Text strings must be rendered within a component.'); - } - } + invariant( + hostContext.isInAParentText, + 'Text strings must be rendered within a component.', + ); + const tag = allocateTag(); UIManager.createView( 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 9f2851382af4..c7e4e3dee1b5 100644 --- a/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js @@ -524,7 +524,7 @@ describe('ReactFabric', () => { }); }); - it('should console error for text not inside of a ancestor', () => { + it('should throw for text not inside of a ancestor', () => { const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({ validAttributes: {}, uiViewClassName: 'RCTScrollView', @@ -542,7 +542,7 @@ describe('ReactFabric', () => { act(() => { ReactFabric.render(this should warn, 11); }); - }).toErrorDev(['Text strings must be rendered within a component.']); + }).toThrow('Text strings must be rendered within a component.'); expect(() => { act(() => { @@ -553,7 +553,7 @@ describe('ReactFabric', () => { 11, ); }); - }).toErrorDev(['Text strings must be rendered within a component.']); + }).toThrow('Text strings must be rendered within a component.'); }); it('should not throw for text inside of an indirect ancestor', () => { diff --git a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js index 4d1ffce09fe3..9026bef79376 100644 --- a/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js +++ b/packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js @@ -473,7 +473,7 @@ describe('ReactNative', () => { ); }); - it('should console error for text not inside of a ancestor', () => { + it('should throw for text not inside of a ancestor', () => { const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({ validAttributes: {}, uiViewClassName: 'RCTScrollView', @@ -487,9 +487,9 @@ describe('ReactNative', () => { uiViewClassName: 'RCTView', })); - expect(() => - ReactNative.render(this should warn, 11), - ).toErrorDev(['Text strings must be rendered within a component.']); + expect(() => ReactNative.render(this should warn, 11)).toThrow( + 'Text strings must be rendered within a component.', + ); expect(() => ReactNative.render( @@ -498,7 +498,7 @@ describe('ReactNative', () => { , 11, ), - ).toErrorDev(['Text strings must be rendered within a component.']); + ).toThrow('Text strings must be rendered within a component.'); }); it('should not throw for text inside of an indirect ancestor', () => {