Commit 5821fca
Reject percentage radius for circle radial gradients (#57874)
Summary:
> [!NOTE]
> Stacked on #57873 (its commit is included here). Without that fix, `circle <length> at <position>` strings would mis-parse into percentage sizes and be wrongly rejected by this validation.
Per [css-images-3 `<radial-size>`](https://www.w3.org/TR/css-images-3/#valdef-radial-size-length-0), a circle's explicit radius must be a `<length>` — percentages are only valid for ellipses. Browsers reject the whole declaration for values like `radial-gradient(circle 50%, red, blue)` (computed `background-image: none`), while React Native accepted them and rendered an arbitrary interpretation (`max` of the value resolved against width and against height). The same style string therefore silently diverged between native and web, contradicting the "Same as web" validation policy this parser already follows for other invalid values.
`processBackgroundImage` now returns no gradient when a circle — explicit (`circle 50%`) or inferred from a single size (`radial-gradient(50%, ...)`, which browsers also reject) — has a percentage size. Ellipses with percentage sizes (`50% 20%`) are unaffected.
Note: the structured C++ parser in `react/renderer/css/CSSBackgroundImage.h` has the same leniency (`CSSRadialGradientExplicitSize` accepts `<length-percentage>` for both axes regardless of shape) and could get the same validation as a follow-up.
## Changelog:
[GENERAL] [FIXED] - Reject percentage radii for circle radial gradients, matching web behavior
Pull Request resolved: #57874
Test Plan:
Added three Fantom tests in `processBackgroundImage-itest.js`: `circle 50%` rejected, inferred-circle `50%` rejected, ellipse `50% 20%` still accepted.
Verified the accept/reject matrix against Chrome (`getComputedStyle(...).backgroundImage === 'none'` for rejected values):
| input | Chrome | RN before | RN after |
| --- | --- | --- | --- |
| `radial-gradient(circle 50%, red, blue)` | rejected | accepted | rejected |
| `radial-gradient(50%, red, blue)` | rejected | accepted | rejected |
| `radial-gradient(50% 20%, red, blue)` | accepted | accepted | accepted |
| `radial-gradient(circle 100px, red, blue)` | accepted | accepted | accepted |
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed By: fabriziocucci
Differential Revision: D115426055
Pulled By: cipolleschi
fbshipit-source-id: 5ba6e2f1d6e36bd5e64d7ef4f917918514f87d811 parent 66f27eb commit 5821fca
2 files changed
Lines changed: 26 additions & 0 deletions
File tree
- packages/react-native/Libraries/StyleSheet
- __tests__
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
986 | 986 | | |
987 | 987 | | |
988 | 988 | | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
989 | 1006 | | |
990 | 1007 | | |
991 | 1008 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
570 | 579 | | |
571 | 580 | | |
572 | 581 | | |
| |||
0 commit comments