Show a soft error when a text string or number is supplied as a child to non text wrappers (#22109)
Sota committed
Aug 16, 2021 at 18:43 UTC
bd255700d73ed5fa88f9e32fa4b43623679adf0c
2 files changed
+8
-9
packages/react-native-renderer/src/ReactFabricHostConfig.js
+5
-6
@@ -22,8 +22,6 @@ import type {
22
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
23
import {create, diff} from './ReactNativeAttributePayload';
24
25
-import invariant from 'shared/invariant';
26
-
25
import {dispatchEvent} from './ReactFabricEventEmitter';
26
27
import {
@@ -264,10 +262,11 @@ export function createTextInstance(
262
hostContext: HostContext,
263
internalInstanceHandle: Object,
264
): TextInstance {
267
- invariant(
268
- hostContext.isInAParentText,
269
- 'Text strings must be rendered within a <Text> component.',
270
- );
265
+ if (__DEV__) {
266
+ if (!hostContext.isInAParentText) {
267
+ console.error('Text strings must be rendered within a <Text> component.');
268
+ }
269
+ }
270
271
const tag = nextReactTag;
272
nextReactTag += 2;
packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js
+3
-3
@@ -524,7 +524,7 @@ describe('ReactFabric', () => {
524
});
525
});
526
527
- it('should throw for text not inside of a <Text> ancestor', () => {
527
+ it('should console error for text not inside of a <Text> ancestor', () => {
528
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
529
validAttributes: {},
530
uiViewClassName: 'RCTScrollView',
@@ -542,7 +542,7 @@ describe('ReactFabric', () => {
542
act(() => {
543
ReactFabric.render(<View>this should warn</View>, 11);
544
});
545
- }).toThrow('Text strings must be rendered within a <Text> component.');
545
+ }).toErrorDev(['Text strings must be rendered within a <Text> component.']);
546
547
expect(() => {
548
act(() => {
@@ -553,7 +553,7 @@ describe('ReactFabric', () => {
553
11,
554
);
555
});
556
- }).toThrow('Text strings must be rendered within a <Text> component.');
556
+ }).toErrorDev(['Text strings must be rendered within a <Text> component.']);
557
});
558
559
it('should not throw for text inside of an indirect <Text> ancestor', () => {