GeezerVison is showing github.com — Show a soft error when a text string or number is supplied as a child… · react/react@e9b2028
File treeExpand file treeCollapse file tree Open diff view settings packages/react-native-renderer/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactFabricHostConfig.js +5-6Lines changed: 5 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,8 +22,6 @@ import type { | 22 | 22 | import {mountSafeCallback_NOT_REALLY_SAFE} from './NativeMethodsMixinUtils'; | 23 | 23 | import {create, diff} from './ReactNativeAttributePayload'; | 24 | 24 |
| 25 | | -import invariant from 'shared/invariant'; | 26 | | - | 27 | 25 | import {dispatchEvent} from './ReactFabricEventEmitter'; | 28 | 26 |
| 29 | 27 | import { | @@ -264,10 +262,11 @@ export function createTextInstance( | 264 | 262 | hostContext: HostContext, | 265 | 263 | internalInstanceHandle: Object, | 266 | 264 | ): 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 | + } | 271 | 270 |
| 272 | 271 | const tag = nextReactTag; | 273 | 272 | nextReactTag += 2; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeHostConfig.js +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -147,11 +147,11 @@ export function createTextInstance( | 147 | 147 | hostContext: HostContext, | 148 | 148 | internalInstanceHandle: Object, | 149 | 149 | ): TextInstance { | 150 | | - invariant( | 151 | | - hostContext.isInAParentText, | 152 | | - 'Text strings must be rendered within a <Text> component.', | 153 | | - ); | 154 | | - | | 150 | + if (__DEV__) { | | 151 | + if (!hostContext.isInAParentText) { | | 152 | + console.error('Text strings must be rendered within a <Text> component.'); | | 153 | + } | | 154 | + } | 155 | 155 | const tag = allocateTag(); | 156 | 156 |
| 157 | 157 | UIManager.createView( | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -524,7 +524,7 @@ describe('ReactFabric', () => { | 524 | 524 | }); | 525 | 525 | }); | 526 | 526 |
| 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', () => { | 528 | 528 | const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({ | 529 | 529 | validAttributes: {}, | 530 | 530 | uiViewClassName: 'RCTScrollView', | @@ -542,7 +542,7 @@ describe('ReactFabric', () => { | 542 | 542 | act(() => { | 543 | 543 | ReactFabric.render(<View>this should warn</View>, 11); | 544 | 544 | }); | 545 | | - }).toThrow('Text strings must be rendered within a <Text> component.'); | | 545 | + }).toErrorDev(['Text strings must be rendered within a <Text> component.']); | 546 | 546 |
| 547 | 547 | expect(() => { | 548 | 548 | act(() => { | @@ -553,7 +553,7 @@ describe('ReactFabric', () => { | 553 | 553 | 11, | 554 | 554 | ); | 555 | 555 | }); | 556 | | - }).toThrow('Text strings must be rendered within a <Text> component.'); | | 556 | + }).toErrorDev(['Text strings must be rendered within a <Text> component.']); | 557 | 557 | }); | 558 | 558 |
| 559 | 559 | it('should not throw for text inside of an indirect <Text> ancestor', () => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/__tests__/ReactNativeMount-test.internal.js +5-5Lines changed: 5 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -473,7 +473,7 @@ describe('ReactNative', () => { | 473 | 473 | ); | 474 | 474 | }); | 475 | 475 |
| 476 | | - it('should throw for text not inside of a <Text> ancestor', () => { | | 476 | + it('should console error for text not inside of a <Text> ancestor', () => { | 477 | 477 | const ScrollView = createReactNativeComponentClass('RCTScrollView', () => ({ | 478 | 478 | validAttributes: {}, | 479 | 479 | uiViewClassName: 'RCTScrollView', | @@ -487,9 +487,9 @@ describe('ReactNative', () => { | 487 | 487 | uiViewClassName: 'RCTView', | 488 | 488 | })); | 489 | 489 |
| 490 | | - expect(() => ReactNative.render(<View>this should warn</View>, 11)).toThrow( | 491 | | - 'Text strings must be rendered within a <Text> component.', | 492 | | - ); | | 490 | + expect(() => | | 491 | + ReactNative.render(<View>this should warn</View>, 11), | | 492 | + ).toErrorDev(['Text strings must be rendered within a <Text> component.']); | 493 | 493 |
| 494 | 494 | expect(() => | 495 | 495 | ReactNative.render( | @@ -498,7 +498,7 @@ describe('ReactNative', () => { | 498 | 498 | </Text>, | 499 | 499 | 11, | 500 | 500 | ), | 501 | | - ).toThrow('Text strings must be rendered within a <Text> component.'); | | 501 | + ).toErrorDev(['Text strings must be rendered within a <Text> component.']); | 502 | 502 | }); | 503 | 503 |
| 504 | 504 | it('should not throw for text inside of an indirect <Text> ancestor', () => { | |
|