GeezerVison is showing github.com — Append text string to <Text> error message (#19581) · react/react@1a41a19
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 +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -244,7 +244,8 @@ export function createTextInstance( | 244 | 244 | ): TextInstance { | 245 | 245 | invariant( | 246 | 246 | hostContext.isInAParentText, | 247 | | - 'Text strings must be rendered within a <Text> component.', | | 247 | + 'Text string must be rendered within a <Text> component.\n\nText: %s', | | 248 | + text.length > 100 ? text.substr(0, 88) + ' (truncated)' : text, | 248 | 249 | ); | 249 | 250 |
| 250 | 251 | const tag = nextReactTag; | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/ReactNativeHostConfig.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -146,7 +146,8 @@ export function createTextInstance( | 146 | 146 | ): TextInstance { | 147 | 147 | invariant( | 148 | 148 | hostContext.isInAParentText, | 149 | | - 'Text strings must be rendered within a <Text> component.', | | 149 | + 'Text string must be rendered within a <Text> component.\n\nText: %s', | | 150 | + text.length > 100 ? text.substr(0, 88) + ' (truncated)' : text, | 150 | 151 | ); | 151 | 152 |
| 152 | 153 | const tag = allocateTag(); | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-native-renderer/src/__tests__/ReactFabric-test.internal.js +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -563,7 +563,15 @@ describe('ReactFabric', () => { | 563 | 563 | })); | 564 | 564 |
| 565 | 565 | expect(() => ReactFabric.render(<View>this should warn</View>, 11)).toThrow( | 566 | | - 'Text strings must be rendered within a <Text> component.', | | 566 | + 'Text string must be rendered within a <Text> component.\n\nText: this should warn', | | 567 | + ); | | 568 | + | | 569 | + expect(() => | | 570 | + ReactFabric.render(<View>{'x'.repeat(200)}</View>, 11), | | 571 | + ).toThrow( | | 572 | + `Text string must be rendered within a <Text> component.\n\nText: ${'x'.repeat( | | 573 | + 88, | | 574 | + )} (truncated)`, | 567 | 575 | ); | 568 | 576 |
| 569 | 577 | expect(() => | @@ -573,7 +581,9 @@ describe('ReactFabric', () => { | 573 | 581 | </Text>, | 574 | 582 | 11, | 575 | 583 | ), | 576 | | - ).toThrow('Text strings must be rendered within a <Text> component.'); | | 584 | + ).toThrow( | | 585 | + 'Text string must be rendered within a <Text> component.\n\nText: hi hello hi', | | 586 | + ); | 577 | 587 | }); | 578 | 588 |
| 579 | 589 | 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 +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -423,7 +423,15 @@ describe('ReactNative', () => { | 423 | 423 | })); | 424 | 424 |
| 425 | 425 | expect(() => ReactNative.render(<View>this should warn</View>, 11)).toThrow( | 426 | | - 'Text strings must be rendered within a <Text> component.', | | 426 | + 'Text string must be rendered within a <Text> component.\n\nText: this should warn', | | 427 | + ); | | 428 | + | | 429 | + expect(() => | | 430 | + ReactNative.render(<View>{'x'.repeat(200)}</View>, 11), | | 431 | + ).toThrow( | | 432 | + `Text string must be rendered within a <Text> component.\n\nText: ${'x'.repeat( | | 433 | + 88, | | 434 | + )} (truncated)`, | 427 | 435 | ); | 428 | 436 |
| 429 | 437 | expect(() => | @@ -433,7 +441,9 @@ describe('ReactNative', () => { | 433 | 441 | </Text>, | 434 | 442 | 11, | 435 | 443 | ), | 436 | | - ).toThrow('Text strings must be rendered within a <Text> component.'); | | 444 | + ).toThrow( | | 445 | + 'Text string must be rendered within a <Text> component.\n\nText: hi hello hi', | | 446 | + ); | 437 | 447 | }); | 438 | 448 |
| 439 | 449 | it('should not throw for text inside of an indirect <Text> ancestor', () => { | |
Collapse file Copy file name to clipboardExpand all lines: scripts/error-codes/codes.json +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 254 | 254 | "253": "work.commit(): Cannot commit while already rendering. This likely means you attempted to commit from inside a lifecycle method.", | 255 | 255 | "254": "Element ref was specified as a string (%s) but no owner was set. This could happen for one of the following reasons:\n1. You may be adding a ref to a functional component\n2. You may be adding a ref to a component that was not created inside a component's render method\n3. You have multiple copies of React loaded\nSee https://reactjs.org/link/refs-must-have-owner for more information.", | 256 | 256 | "255": "Expected ReactFbErrorUtils.invokeGuardedCallback to be a function.", | 257 | | - "256": "Expected ReactFiberErrorDialog.showErrorDialog to be a function.", | 258 | 257 | "257": "Portals are not currently supported by the server renderer. Render them conditionally so that they only appear on the client render.", | 259 | 258 | "258": "Unknown element-like object type: %s. This is likely a bug in React. Please file an issue.", | 260 | 259 | "259": "The experimental Call and Return types are not currently supported by the server renderer.", | | 270 | 269 | "269": "Profiler must specify an \"id\" string and \"onRender\" function as props", | 271 | 270 | "270": "The current renderer does not support persistence. This error is likely caused by a bug in React. Please file an issue.", | 272 | 271 | "271": "Failed to replay rendering after an error. This is likely caused by a bug in React. Please file an issue with a reproducing case to help us find it.", | 273 | | - "272": "The current renderer does not support hydration. This error is likely caused by a bug in React. Please file an issue.", | 274 | 272 | "273": "Nesting of <View> within <Text> is not currently supported.", | 275 | 273 | "274": "Text strings must be rendered within a <Text> component.", | 276 | 274 | "275": "The current renderer does not support mutation. This error is likely caused by a bug in React. Please file an issue.", | | 361 | 359 | "367": "ReactDOM.createEventHandle: setListener called on an element target that is not managed by React. Ensure React rendered the DOM element.", | 362 | 360 | "368": "ReactDOM.createEventHandle: setListener called on an invalid target. Provide a valid EventTarget or an element managed by React.", | 363 | 361 | "369": "ReactDOM.createEventHandle: setter called on an invalid target. Provide a valid EventTarget or an element managed by React.", | 364 | | - "370": "ReactDOM.createEventHandle: setter called with an invalid callback. The callback must be a function." | | 362 | + "370": "ReactDOM.createEventHandle: setter called with an invalid callback. The callback must be a function.", | | 363 | + "371": "Text string must be rendered within a <Text> component.\n\nText: %s" | 365 | 364 | } |
|