Skip to content

[iOS] Fix NaN passed to CoreGraphics for outset boxShadow with negative spread on small views - #60323

Merged
meta-codesync[bot] merged 1 commit into
react:mainfrom
harpreetkbadhan:fix/ios-outset-box-shadow-negative-spread
Dec 1, 2026
Merged

meta-codesync[bot] merged 1 commit into
react:mainfrom
harpreetkbadhan:fix/ios-outset-box-shadow-negative-spread

Conversation

@harpreetkbadhan

@harpreetkbadhan harpreetkbadhan commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fixes #60302.

On iOS, an outset boxShadow with a negative spread logs CoreGraphics invalid numeric value (NaN) errors when the view is smaller than twice the spread on either axis. The most common case is a view with zero size, such as the first frame of a measure-then-animate indicator. Tailwind's shadow-sm is enough to trigger it, because its second layer has -1px spread.

RCTGetOutsetBoxShadowLayer builds the shadow rect with CGRectInset(bounds, -spread, -spread). When that would make the width or height negative, CGRectInset returns CGRectNull (origin at infinity). The null rect then goes into RCTPathCreateWithRoundedRect for both the shadow path and the padded mask path, and CGPathAddArc receives NaN. This has been happening since #50636 (0.80). Before that, the shadow rect size was clamped with fmax(…, 0).

This change caps each axis's inset at half the layer's size, so a negative spread can shrink the rect to zero but not past it. The rect stays centred on the layer, as in 0.79. For any spread that doesn't overshrink the rect, CGRectInset gets exactly the same arguments as before, so zero, positive and small negative spreads are unchanged. With a zero-sized rect, RCTPathCreateWithRoundedRect already clamps every corner radius to 0, so no NaN reaches CoreGraphics. The inset branch in the same file already handles this case with a CGRectIsNull check.

Changelog:

[IOS] [FIXED] - Fix NaN passed to CoreGraphics when an outset boxShadow with negative spread is applied to a view smaller than the spread, e.g. a zero-sized view

Test Plan:

Added React/Tests/Fabric/RCTBoxShadowTests.mm (5 tests), which checks the shadow path and mask path bounds from RCTGetBoxShadowLayer:

  • a zero-sized layer with negative spread gives an empty shadow rect at the offset, and the mask still includes the padded rect
  • each axis is clamped on its own (100×1 layer with -1 spread → 98×0 rect, centred)
  • small negative, zero and positive spread give the same rects as before

To run them, I enabled the React-RCTFabric test spec locally (:testspecs => ['Tests'] in scripts/cocoapods/fabric.rb), ran pod install in packages/rn-tester (plus pod update hermes-engine --no-repo-update to match the local Hermes version), then:

xcodebuild test -workspace RNTesterPods.xcworkspace -scheme React-RCTFabric-Unit-Tests -destination 'platform=iOS Simulator,…'
  • Before the fix: 3 of 5 new tests fail. The shadow path bounds are {{inf, inf}, {0, 0}}, and the log has 16 invalid numeric value (NaN…) to CoreGraphics API messages, 8 per failing test, matching the issue's 2 paths × 4 corner arcs.
  • After the fix: Executed 27 tests, with 0 failures, covering all of React/Tests/Fabric, including the existing RCTGradientUtilsTests and AppleEventBeatTests. No CoreGraphics NaN messages.

Notes:

  • CI does not build this test spec, the same as RCTGradientUtilsTests (Interpolate gradient color stops outside the 0–100% range #59774).
  • With the full Tests/**/*.mm glob, the test spec currently fails to compile on main for an unrelated reason: React/Tests/Text/RCTSelectableParagraphComponentViewTests.mm can't find react/renderer/element/ComponentBuilder.h. I narrowed the glob to Tests/Fabric/*.mm locally to run these tests. That change is not part of this PR.
  • yarn format-check-cpp passes.
  • Not run: the issue's Snack in RNTester while watching the simulator logs.
A negative spread larger than half the view made CGRectInset return
CGRectNull, which reached CGPathAddArc as NaN. Cap each axis's inset at
half the layer size so the rect collapses to zero, centred on the layer,
as it did before react#50636. Fixes react#60302.
@meta-cla

meta-cla Bot commented Nov 26, 2026

Copy link
Copy Markdown

Hi @harpreetkbadhan!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 26, 2026
@meta-cla

meta-cla Bot commented Nov 26, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 26, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 26, 2026
@meta-codesync

meta-codesync Bot commented Nov 30, 2026

Copy link
Copy Markdown

@javache has imported this pull request. If you are a Meta employee, you can view this in D135061332.

@github-actions

Copy link
Copy Markdown

Visual regression

No visual differences at 82e10848724c.

android: no capture

@zeyap zeyap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync
meta-codesync Bot merged commit 0fcf6ec into react:main Dec 1, 2026
93 of 95 checks passed
@react-native-bot

Copy link
Copy Markdown
Collaborator
@react-native-bot react-native-bot added the Merged This PR has been merged. label Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

3 participants