Skip to content

Commit

Permalink
Show a soft error when a text string or number is supplied as a child…
Browse files Browse the repository at this point in the history
… to non text wrappers (#22109)
  • Loading branch information
sota000 committed Aug 17, 2021
1 parent 424fe58 commit bd25570
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,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 {
Expand Down Expand Up @@ -264,10 +262,11 @@ export function createTextInstance(
hostContext: HostContext,
internalInstanceHandle: Object,
): TextInstance {
invariant(
hostContext.isInAParentText,
'Text strings must be rendered within a <Text> component.',
);
if (__DEV__) {
if (!hostContext.isInAParentText) {
console.error('Text strings must be rendered within a <Text> component.');
}
}

const tag = nextReactTag;
nextReactTag += 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ describe('ReactFabric', () => {
});
});

it('should throw for text not inside of a <Text> ancestor', () => {
it('should console error for text not inside of a <Text> ancestor', () => {
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
validAttributes: {},
uiViewClassName: 'RCTScrollView',
Expand All @@ -542,7 +542,7 @@ describe('ReactFabric', () => {
act(() => {
ReactFabric.render(<View>this should warn</View>, 11);
});
}).toThrow('Text strings must be rendered within a <Text> component.');
}).toErrorDev(['Text strings must be rendered within a <Text> component.']);

expect(() => {
act(() => {
Expand All @@ -553,7 +553,7 @@ describe('ReactFabric', () => {
11,
);
});
}).toThrow('Text strings must be rendered within a <Text> component.');
}).toErrorDev(['Text strings must be rendered within a <Text> component.']);
});

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

0 comments on commit bd25570

Please sign in to comment.