Skip to content

Commit 079e4ea

Browse files
author
Brian Vaughn
committed
Replaced warning() with console.error()
1 parent b810501 commit 079e4ea

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import ReactFiberReconciler from 'react-reconciler';
2323

2424
import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev';
2525
import emptyObject from 'fbjs/lib/emptyObject';
26-
import warning from 'fbjs/lib/warning';
2726

2827
// Modules provided by RN:
2928
import TextInputState from 'TextInputState';
@@ -155,10 +154,13 @@ const ReactFabricRenderer = ReactFiberReconciler({
155154
}
156155
}
157156

158-
warning(
159-
type !== 'RCTView' || !hostContext.isInAParentText,
160-
'Nesting of <View> within <Text> is not currently supported.',
161-
);
157+
if (type === 'RCTView' && hostContext.isInAParentText) {
158+
// Intentional use of console.error() rather than fbjs warning(),
159+
// So that React Native redbox is used (rather than yellow box).
160+
console.error(
161+
'Nesting of <View> within <Text> is not currently supported.',
162+
);
163+
}
162164
}
163165

164166
const updatePayload = ReactNativeAttributePayload.create(
@@ -189,10 +191,13 @@ const ReactFabricRenderer = ReactFiberReconciler({
189191
internalInstanceHandle: Object,
190192
): TextInstance {
191193
if (__DEV__) {
192-
warning(
193-
hostContext.isInAParentText,
194-
'Text strings must be rendered within a <Text>.',
195-
);
194+
if (!hostContext.isInAParentText) {
195+
// Intentional use of console.error() rather than fbjs warning(),
196+
// So that React Native redbox is used (rather than yellow box).
197+
console.error(
198+
'Text strings must be rendered within a <Text> component.',
199+
);
200+
}
196201
}
197202

198203
const tag = nextReactTag;

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
1212
import ReactFiberReconciler from 'react-reconciler';
1313
import emptyObject from 'fbjs/lib/emptyObject';
1414
import invariant from 'fbjs/lib/invariant';
15-
import warning from 'fbjs/lib/warning';
15+
1616
// Modules provided by RN:
1717
import UIManager from 'UIManager';
1818
import deepFreezeAndThrowOnMutationInDev from 'deepFreezeAndThrowOnMutationInDev';
@@ -89,10 +89,13 @@ const NativeRenderer = ReactFiberReconciler({
8989
}
9090
}
9191

92-
warning(
93-
type !== 'RCTView' || !hostContext.isInAParentText,
94-
'Nesting of <View> within <Text> is not currently supported.',
95-
);
92+
if (type === 'RCTView' && hostContext.isInAParentText) {
93+
// Intentional use of console.error() rather than fbjs warning(),
94+
// So that React Native redbox is used (rather than yellow box).
95+
console.error(
96+
'Nesting of <View> within <Text> is not currently supported.',
97+
);
98+
}
9699
}
97100

98101
const updatePayload = ReactNativeAttributePayload.create(
@@ -124,10 +127,13 @@ const NativeRenderer = ReactFiberReconciler({
124127
internalInstanceHandle: Object,
125128
): TextInstance {
126129
if (__DEV__) {
127-
warning(
128-
hostContext.isInAParentText,
129-
'Text strings must be rendered within a <Text>.',
130-
);
130+
if (!hostContext.isInAParentText) {
131+
// Intentional use of console.error() rather than fbjs warning(),
132+
// So that React Native redbox is used (rather than yellow box).
133+
console.error(
134+
'Text strings must be rendered within a <Text> component.',
135+
);
136+
}
131137
}
132138

133139
const tag = allocateTag();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ describe('ReactFabric', () => {
321321

322322
expect(() =>
323323
ReactFabric.render(<View>this should warn</View>, 11),
324-
).toWarnDev('Text strings must be rendered within a <Text>.');
324+
).toWarnDev('Text strings must be rendered within a <Text> component.');
325325

326326
expect(() =>
327327
ReactFabric.render(
@@ -330,7 +330,7 @@ describe('ReactFabric', () => {
330330
</Text>,
331331
11,
332332
),
333-
).toWarnDev('Text strings must be rendered within a <Text>.');
333+
).toWarnDev('Text strings must be rendered within a <Text> component.');
334334
});
335335

336336
it('should not warn warn about text inside of an indirect <Text> ancestor', () => {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe('ReactNative', () => {
231231

232232
expect(() =>
233233
ReactNative.render(<View>this should warn</View>, 11),
234-
).toWarnDev('Text strings must be rendered within a <Text>.');
234+
).toWarnDev('Text strings must be rendered within a <Text> component.');
235235

236236
expect(() =>
237237
ReactNative.render(
@@ -240,7 +240,7 @@ describe('ReactNative', () => {
240240
</Text>,
241241
11,
242242
),
243-
).toWarnDev('Text strings must be rendered within a <Text>.');
243+
).toWarnDev('Text strings must be rendered within a <Text> component.');
244244
});
245245

246246
it('should not warn warn about text inside of an indirect <Text> ancestor', () => {

0 commit comments

Comments
 (0)