Skip to content

Commit bd25570

Browse files
authored
Show a soft error when a text string or number is supplied as a child to non text wrappers (#22109)
1 parent 424fe58 commit bd25570

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

packages/react-native-renderer/src/ReactFabricHostConfig.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import type {
2222
import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils';
2323
import {create, diff} from './ReactNativeAttributePayload';
2424

25-
import invariant from 'shared/invariant';
26-
2725
import {dispatchEvent} from './ReactFabricEventEmitter';
2826

2927
import {
@@ -264,10 +262,11 @@ export function createTextInstance(
264262
hostContext: HostContext,
265263
internalInstanceHandle: Object,
266264
): 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+
}
271270

272271
const tag = nextReactTag;
273272
nextReactTag += 2;

packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ describe('ReactFabric', () => {
524524
});
525525
});
526526

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', () => {
528528
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
529529
validAttributes: {},
530530
uiViewClassName: 'RCTScrollView',
@@ -542,7 +542,7 @@ describe('ReactFabric', () => {
542542
act(() => {
543543
ReactFabric.render(<View>this should warn</View>, 11);
544544
});
545-
}).toThrow('Text strings must be rendered within a <Text> component.');
545+
}).toErrorDev(['Text strings must be rendered within a <Text> component.']);
546546

547547
expect(() => {
548548
act(() => {
@@ -553,7 +553,7 @@ describe('ReactFabric', () => {
553553
11,
554554
);
555555
});
556-
}).toThrow('Text strings must be rendered within a <Text> component.');
556+
}).toErrorDev(['Text strings must be rendered within a <Text> component.']);
557557
});
558558

559559
it('should not throw for text inside of an indirect <Text> ancestor', () => {

0 commit comments

Comments
 (0)