Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show a soft error when a text string or number is supplied as a child… #22109

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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 {
Expand Down Expand Up @@ -251,10 +249,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 @@ -665,7 +665,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 @@ -683,7 +683,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 @@ -694,7 +694,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