Skip to content

Commit

Permalink
Revert "Show a soft error when a text string or number is supplied as…
Browse files Browse the repository at this point in the history
… a child to non text wrappers (#21953)" (#22108)

This reverts commit e9b2028.
  • Loading branch information
sota000 authored Aug 17, 2021
1 parent aebf3b4 commit 424fe58
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
11 changes: 6 additions & 5 deletions packages/react-native-renderer/src/ReactFabricHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 <Text> component.');
}
}
invariant(
hostContext.isInAParentText,
'Text strings must be rendered within a <Text> component.',
);

const tag = nextReactTag;
nextReactTag += 2;
Expand Down
10 changes: 5 additions & 5 deletions packages/react-native-renderer/src/ReactNativeHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Text> component.');
}
}
invariant(
hostContext.isInAParentText,
'Text strings must be rendered within a <Text> component.',
);

const tag = allocateTag();

UIManager.createView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ describe('ReactFabric', () => {
});
});

it('should console error for text not inside of a <Text> ancestor', () => {
it('should throw 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);
});
}).toErrorDev(['Text strings must be rendered within a <Text> component.']);
}).toThrow('Text strings must be rendered within a <Text> component.');

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

it('should not throw for text inside of an indirect <Text> ancestor', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ describe('ReactNative', () => {
);
});

it('should console error for text not inside of a <Text> ancestor', () => {
it('should throw for text not inside of a <Text> ancestor', () => {
const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({
validAttributes: {},
uiViewClassName: 'RCTScrollView',
Expand All @@ -487,9 +487,9 @@ describe('ReactNative', () => {
uiViewClassName: 'RCTView',
}));

expect(() =>
ReactNative.render(<View>this should warn</View>, 11),
).toErrorDev(['Text strings must be rendered within a <Text> component.']);
expect(() => ReactNative.render(<View>this should warn</View>, 11)).toThrow(
'Text strings must be rendered within a <Text> component.',
);

expect(() =>
ReactNative.render(
Expand All @@ -498,7 +498,7 @@ describe('ReactNative', () => {
</Text>,
11,
),
).toErrorDev(['Text strings must be rendered within a <Text> component.']);
).toThrow('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 424fe58

Please sign in to comment.