Commit d7b5314
Skip cloneElement for Fragment children in TouchableHighlight (#56539)
Summary:
Fixes #54933.
Passing a `React.Fragment` as the child of `TouchableHighlight` currently produces this warning:
Warning: Invalid prop `style` supplied to `React.Fragment`.
React.Fragment can only have `key` and `children` props.
This happens because `TouchableHighlight` unconditionally calls `cloneElement(child, {style})` on its single child, including when that child is a Fragment.
This PR skips that clone when `child.type === React.Fragment` and renders the Fragment as-is.
That avoids passing an invalid `style` prop to `React.Fragment` while preserving the existing render path for Fragment children.
## Changelog:
[General] [Fixed] - Suppress `React.Fragment` style warning when used as a child of `TouchableHighlight`
Pull Request resolved: #56539
Test Plan:
- Added a Fantom regression test in `TouchableHighlight-itest.js` that renders `<TouchableHighlight><Fragment>...</Fragment></TouchableHighlight>`
- Verified the expected rendered output
- Verified `console.error` is not called
- `yarn flow focus-check packages/react-native/Libraries/Components/Touchable/TouchableHighlight.js`
- `yarn lint` on the changed files
- `yarn prettier --list-different` on the changed files
Reviewed By: GijsWeterings
Differential Revision: D104224036
Pulled By: javache
fbshipit-source-id: 17289926bc62cda84decaf7154183ff355a03d211 parent 41fc7fd commit d7b5314
2 files changed
Lines changed: 58 additions & 6 deletions
File tree
- packages/react-native/Libraries/Components/Touchable
- __tests__
Lines changed: 16 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
305 | 306 | | |
306 | 307 | | |
307 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
308 | 316 | | |
309 | 317 | | |
310 | 318 | | |
| |||
377 | 385 | | |
378 | 386 | | |
379 | 387 | | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
386 | 396 | | |
387 | 397 | | |
388 | 398 | | |
| |||
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
398 | 440 | | |
399 | 441 | | |
400 | 442 | | |
| |||
0 commit comments