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/ReactNativeHostConfig.js b/packages/react-native-renderer/src/ReactNativeHostConfig.js index 205f8189b7a7c..63337a04df1af 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 { - 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 = 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 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', () => { 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 9026bef793767..4d1ffce09fe35 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 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', @@ -487,9 +487,9 @@ describe('ReactNative', () => { uiViewClassName: 'RCTView', })); - expect(() => ReactNative.render(this should warn, 11)).toThrow( - 'Text strings must be rendered within a component.', - ); + expect(() => + ReactNative.render(this should warn, 11), + ).toErrorDev(['Text strings must be rendered within a component.']); expect(() => ReactNative.render( @@ -498,7 +498,7 @@ describe('ReactNative', () => { , 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', () => {