14921 Commits
Author SHA1 Message Date
React Native Bot c30b7f8685 Release 0.88.1
#publish-packages-to-npm&latest
2026-10-27 12:09:29 +00:00
Alan Hughes 8aea8d9bad Fix StatusBar style and visibility on iOS 27 (#58926)
Summary:
Fixes https://github.com/react/react-native/issues/58758.
In apps built with the iOS 27 SDK, `StatusBar.setBarStyle` and `StatusBar.setHidden` do nothing. `RCTStatusBarManager` uses the `UIApplication` status bar setters, and UIKit turns them into no-ops for apps linked against the iOS 27 SDK. Apps built with the iOS 26 SDK are not affected. A plain UIKit app built with the iOS 27 SDK shows that with `UIViewControllerBasedStatusBarAppearance` set to `NO`, nothing can change the status bar on iOS 27. With `YES`, the view controller methods still work.

This change moves `StatusBar` to the view controller model. The module stores the requested style, hidden state, and animation in a new `RCTStatusBarAppearance` class and calls `setNeedsStatusBarAppearanceUpdate` on the presented view controller. The default root view controller from `RCTDefaultReactNativeFactoryDelegate` and the Fabric modal controller return those values. The modal keeps the status bar that was on screen when it opened until JS changes it, so a status bar set natively (ie by react-native-screens) is not lost. With `NO`, the module still calls the `UIApplication` setters, so apps built with older SDKs keep working. When React Native is built with the iOS 27 SDK and runs on iOS 27, it also logs one warning that tells the developer to set the key to `YES`.

Apps that override `createRootViewController` need their view controller to return the `RCTStatusBarAppearance` values for `StatusBar` to work on iOS 27.

A similar change, https://github.com/react/react-native/issues/25919, landed in March 2020 and was reverted the next day

[IOS] [FIXED] - `StatusBar` style and visibility work on iOS 27 for apps built with the iOS 27 SDK when `UIViewControllerBasedStatusBarAppearance` is `YES`. Custom root view controllers must return the `RCTStatusBarAppearance` values.

Pull Request resolved: https://github.com/react/react-native/pull/58926

Test Plan:
12 new XCTest cases in `RCTStatusBarAppearanceTests`. The OSS XCTest file has no internal BUCK owner and was not run locally.

Validation for the review update:
- Applied the explicit legacy-API guard to both `setStyle:animated:` and `setHidden:withAnimation:`. The appearance-state update remains unconditional; UIKit setters and warnings remain limited to apps using app-level status bar appearance.
- Meta-managed `clang-format` and `arc lint` passed for `RCTStatusBarManager.mm`.
- Built `ReactApple`, `CoreModulesApple`, `RCTFabricApple` and `RCTAppDelegateApple` for `iphonesimulator-arm64` with annotation checks enabled.
- No public headers changed, so API snapshots are unchanged.
- Diff-time CI will rerun for the updated code.

Reviewed By: javache

Differential Revision: D127555263

Pulled By: cipolleschi

fbshipit-source-id: 9a6d21236987e309917e620387b34e88e7da24c7
(cherry picked from commit bd08dafc98)
2026-10-26 16:01:49 +00:00
Riccardo Cipolleschi 9d01a6a1b0 Bump Hermes to 260318099.0.5
Picks up hermes-v260318099.0.5, which carries:

- Fix external ArrayBuffer context lookup
- Fix handle accumulation in (de)serialization loops
- Fix BigInt deserialization
- Fix out-of-bounds dense store for array literals with more than 65535 elements
- Fix array literal length when a hole precedes a spread
- GC: skip the HV64 dead-zone freelist bucket in OldGen::search (performance)
- The JSI changes picked into 0.88-stable in #1477-#1482, so React Native's
  JSI and Hermes' JSI stay identical

Also brings sdks/.hermesv1version, which still named hermes-v260318099.0.2, in
line with the pinned version. The .0.3 and .0.4 bumps did not update it, so
builds of Hermes from source were still using .0.2.
2026-10-26 15:23:05 +00:00
nishan (o^▽^o) c904aa46ef fix(iOS) - Prevent SwiftUI based filter from insetting content by the safe area (#58349)
Summary:
When a `filter` style is passed to a `View`, it can shift the `View` by safe area insets if it overlaps a safe area edge. Filter style should not affect layout. Also fixes - https://github.com/react/react-native/issues/57642

Unset [safeAreaRegions](https://developer.apple.com/documentation/swiftui/uihostingcontroller/safearearegions) on the hosting controller to opt out of implicit safe area insets. Below iOS 16.4 `safeAreaRegions` does not exist so it requires Obj-C swizzling hack as noted here - https://github.com/react/react-native/pull/57643. Hence, proper fix requires gating the filter feature to iOS 16.4. We can mention it in the documentation on release.

## Changelog:

[IOS] [FIXED] - Fix views with a filter having their content offset by the safe area insets

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests

Pull Request resolved: https://github.com/react/react-native/pull/58349

Test Plan:
- Set `releaseLevel` to canary.
- Render `<View style={{width: 100, height: 100, backgroundColor:"red", filter:[{blur: 10}]}} />` in RNTester, make sure it renders on top of the screen.
- View renders as expected on first mount.
- Change height or width, it will shift the view by safe area inset. It requires layout update because RCTMountingManager calls `finalizeUpdates` before calling `mountChildComponentView`, so on first mount the hosting view has no window and its safe area insets are zero.

| Before | After |
| --- | --- |
| <img width="200" alt="Filtered content pushed down by the top safe area inset" src="https://github.com/user-attachments/assets/49905f7b-0a82-4958-91d2-e89c852e5a93" /> | <img width="200" alt="Filtered content aligned with the view bounds" src="https://github.com/user-attachments/assets/85848179-43fc-42f4-9271-1093413ad42d" /> |
| Content is offset down and shrunk by the top inset | Content fills the view |

cc - jorge-cab

Reviewed By: christophpurrer

Differential Revision: D119153463

Pulled By: cipolleschi

fbshipit-source-id: edabd933b4928dd023109eba5d09b6447256615f
(cherry picked from commit fea820fa9b)
2026-10-26 15:08:19 +00:00
Gang Zhao 1a5311368f Run the API tests on the sandbox (#59238)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/59238

Add HermesSandboxRuntime to runtimeGenerators() in APITestFactory.cpp,
so HermesUnitTests runs the parameterized HermesRuntimeTest cases on
the sandbox as well, like the legacy Hermes API tests do. Until now no
static_h test ran the sandbox.

The sandbox does not support everything HermesRuntime does, so the
tests skip what it lacks, with the same
dynamic_cast<HermesSandboxRuntime *> checks the file already uses:
- instrumentation(): GetHeapInfo and ExternalMemoryNoOpTest.
- ArrayBuffers created from a MutableBuffer: the rest of
  TryGetMutableBuffer after its first check, and
  TryGetMutableBufferAfterHiddenClassTransition.
- createValueFromJsonUtf8 is the default implementation, which calls
  the global JSON.parse: CreateValueFromJsonUtf8IgnoresGlobalJSON.
- utf16() converts through UTF-8, which turns lone surrogates into
  U+FFFD: the lone surrogate checks at the end of UTF16ConversionTest
  and CreateFromUtf16Test.

The sandbox implements neither ISerialization nor Worker, so
HermesSerializationTest and HermesWorkerTest run on the new
hermesRuntimeGenerators(), which returns just the two HermesRuntime
factories.

The same factory backs JSITests-SHTrunk, JSITestsUnstable-SHTrunk and
JSIDynamicTests-SHTrunk in xplat/jsi, FBJSValueTests-SHTrunk on Apple,
and the CMake APITests, so those now run on the sandbox too. In
testlib, ArrayBufferDetachedTest assumed that a runtime with
ArrayBuffer.prototype.detached can also detach a buffer from JS. The
sandbox has neither transfer() nor HermesInternal.detachArrayBuffer,
so the test now stops after its first check in that case.

The CMake sanitizer jobs build with Clang's UBSan, whose function
type check aborts on the generated code's indirect calls: they pass
the instance as void * to functions defined with a typed instance
pointer. Nothing ran the sandbox before, so this never fired. Build
the generated C with -fno-sanitize=function under Clang.

Changelog: [Internal]

Reviewed By: avp

Differential Revision: D125561036

fbshipit-source-id: 65d82faf50745489321a04a3b12162d3f4983be4
(cherry picked from commit 05a2e4c799)
2026-10-26 13:36:39 +00:00
Gang Zhao 39276e6d70 Fix: JSI Value::toString() should check the result type (#59146)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/59146

`global.String` could be overridden. We always need to check the return type before casting to `jsi::String`.

Changelog: [Internal]

Reviewed By: avp

Differential Revision: D125707029

fbshipit-source-id: 15d3f83ac23d8bceb24e9e13a1f67dc4b61bb3b8
(cherry picked from commit 1fcf9b87c8)
2026-10-26 13:36:39 +00:00
Marc Rousavy 4292cc3bc4 Forward createValueFromJsonUtf8 in RuntimeDecorator (#58960)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/58960

`RuntimeDecorator` doesn't forward `createValueFromJsonUtf8` to the plain runtime, so decorated runtimes use the `JSON.parse`-based default from jsi.cpp instead of the plain runtime's parser. For Hermes that means `makeThreadSafeHermesRuntime` and anything built on `WithRuntimeDecorator` never reach the native parser from a3f615cec.

I think this was missed rather than chosen. `WithRuntimeDecorator` already overrides it (added in c2a0da2ae as `Around` plus `RD::createValueFromJsonUtf8`), which only makes sense if `RuntimeDecorator` forwards it. Today that `RD::` call lands in the default, so it takes one `Around` plus several nested ones for `global`, `getProperty`, `createStringFromUtf8` and `call`. It's also observable: on a thread-safe runtime, after `JSON.parse = () => 'hijacked'`, `Value::createFromJsonUtf8` returns `'hijacked'`, and after `delete globalThis.JSON` it throws. A plain `HermesRuntime` parses normally in both cases.

`TracingRuntime` relies on the current behavior. JSON parsing only shows up in traces because the default splits into traced `global`/`getProperty`/`call` calls. Forwarding alone would hand back a value from the plain runtime with no def, and replay would hit the "has no def" assert in `useObjectID`. So `TracingRuntime` now overrides `createValueFromJsonUtf8` and calls `jsi::Runtime::createValueFromJsonUtf8` explicitly. That runs the same code as before, so traces are unchanged and there's no new record type. If you'd prefer a dedicated SynthTrace record I can do that instead.

A side effect: decorators that watched JSON parsing through `global`/`getProperty`/`call` now need to override `createValueFromJsonUtf8`, like every other forwarded method. For example, `TimedRuntime` no longer counts JSON parsing under its `call` timer. The other methods decorators don't forward yet are the `createError*` family (https://github.com/facebook/hermes/issues/2203) and `String::length` (https://github.com/facebook/hermes/issues/2205). React Native's `decorator.h` has the same gap.

X-link: https://github.com/facebook/hermes/pull/2206

Test Plan:
New tests:
- `JSITest.CreateValueFromJsonUtf8Test` checks that parsing through a `RuntimeDecorator` reaches the wrapped runtime, and keeps coverage of the jsi.cpp default through a decorator that overrides back to it. It calls `outer.createValueFromJsonUtf8` directly to check that the override remains public.
- `HermesRuntimeTest.CreateValueFromJsonUtf8IgnoresGlobalJSON` replaces `JSON.parse` and checks that parsing still works, on the plain and thread-safe runtimes.
- `SynthTraceReplayTest.CreateValueFromJsonUtf8Replay` parses on the tracing runtime, uses the result from native code, and replays with verification.

Without the change the first two fail (the second only on the thread-safe runtime). With only the `decorator.h` part, the SynthTrace test aborts in `useObjectID`. With the full change all pass, and so does the full `APITests` binary (360 tests) in a Debug + ASan build. `APILeanTests` also passes.

The direct call fails to compile with the previous header because `createValueFromJsonUtf8` is protected. With this revision, `cmake --build cmake-build-asan --target check-hermes -j 12` passes in Debug + ASan: 4,126 expected passes, 6 expected failures, and 197 unsupported tests. Node-API checks: 41 passes and 23 skips.

Reviewed By: javache

Differential Revision: D124177263

Pulled By: lavenzg

fbshipit-source-id: 973dc8b3c69002a81e634bb6c992f5f167e13bf2
(cherry picked from commit b5eec4e4f3)
2026-10-26 13:36:38 +00:00
Marc Rousavy 06e8e082ed Use createError in JSError and forward it in RuntimeDecorator (#58961)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/58961

`JSError(rt, message)` still creates its value by looking up `globalThis.Error` and calling it, which predates `IRuntime::createError`. It now uses `rt.createError(...)` like the `JSError::createXError` factories, with the same try/catch fallback. The default `Runtime::createError` makes the same global call, so runtimes without a native implementation behave as before. On Hermes every `JSError` thrown from native code skips a global lookup and a JS call, and `message`, `stack` and `what()` come out the same.

`RuntimeDecorator` and `WithRuntimeDecorator` didn't forward the `createError` family, so decorated runtimes (the thread-safe runtime, `TracingRuntime`) quietly fell back to the global constructor calls. They forward to `plain()` now, through `Around` for `WithRuntimeDecorator`, and they're public like in `jsi::Runtime`.

One visible difference on Hermes, same as the other `createXError` APIs: if user code replaced or deleted `globalThis.Error`, `JSError(rt, message)` no longer calls the replacement and creates a real `Error` anyway.

X-link: https://github.com/facebook/hermes/pull/2203

Test Plan:
Two new tests in testlib.cpp. `JSErrorMessageTest` checks the value is an `Error` with the right message and a string stack, and that a counting `globalThis.Error` replacement gets called exactly as often as `rt.createError` calls it, so it holds for native and default implementations. `DecoratorCreateErrorTest` checks that all seven `createXError` calls, and `JSError`, reach the wrapped runtime once through both decorators, and that `Around` runs once.

`JSErrorDoesNotInfinitelyRecurse` and `CreateJSErrorPropagatesOOMExceptionTest` run through decorators that use the default `Runtime::createError`. This keeps the missing-constructor fallback and OOM propagation covered, since both tests depend on changing `globalThis.Error`.

`APITests` (ASan + Debug, macOS arm64, `HERMESVM_EXCEPTION_ON_OOM=ON`): 362/362 pass, including SynthTrace and all three OOM tests. Built with `-O1` and `HERMES_ENABLE_WERROR=ON`; the existing GoogleTest `uninitialized-const-pointer` warning is demoted for AppleClang 21.

```sh
cmake --build cmake-build-asan-oom --target APITests -j 8
cmake-build-asan-oom/unittests/API/APITests
```

Before the OOM test adaptation, `CreateJSErrorPropagatesOOMExceptionTest` fails because it throws `JSError` instead of `JSOutOfMemoryError`. It passes with the decorator. The earlier checks with the `jsi.cpp` and `decorator.h` changes reverted also made the new JSI tests fail.

Reviewed By: javache

Differential Revision: D124178378

Pulled By: lavenzg

fbshipit-source-id: 33fa348abc52e21626f68d6509093313ab438d87
(cherry picked from commit 0cca3a1f77)
2026-10-26 13:36:38 +00:00
Marc Rousavy 80b869c26d Run the With hooks around WithRuntimeDecorator::createArrayBuffer (#58935)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/58935

`WithRuntimeDecorator` wraps every override in `Around around{with_};` except `createArrayBuffer(std::shared_ptr<MutableBuffer>)`, which calls `RD::createArrayBuffer` directly. It has been like that since external ArrayBuffers were added in https://github.com/facebook/hermes/issues/793, where the overrides next to it did get the guard. `HermesRuntimeImpl::createArrayBuffer` allocates a `JSArrayBuffer` on the GC heap, so on `makeThreadSafeHermesRuntime` it runs without the runtime lock, and reentrancy checks built on `WithRuntimeDecorator` never see the call.

facebook/react-native#45042 and facebook/react-native#45049 fixed the same kind of gap for methods that had no `WithRuntimeDecorator` override at all. This one has an override that just skips the guard, so it wasn't caught there.

A small stress program shows the race: one thread runs an allocating JS loop on a thread-safe runtime while another creates external ArrayBuffers. In a Debug build it fails the `makeA() calls can not be interleaved` assert in HadesGC. With the guard it runs clean. I didn't add it as a test because it depends on timing. React Native's copy of `decorator.h` has the same line.

X-link: https://github.com/facebook/hermes/pull/2204

Test Plan:
Added `HermesRuntimeDecoratorTest.CreateArrayBufferCallsWith`. It wraps `makeHermesRuntime()` in a counting `WithRuntimeDecorator`, creates an ArrayBuffer from a `MutableBuffer`, and checks that `before()` and `after()` each ran once. Without the change both counts are 0 and the test fails. With it the test passes, and so does the full `APITests` binary (356 tests) in a Debug + ASan build.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed By: avp

Differential Revision: D123939407

Pulled By: lavenzg

fbshipit-source-id: 165a7807ecc9cf68f56a1f2b188642dbd68d136d
(cherry picked from commit 82def6ea4c)
2026-10-26 13:36:38 +00:00
Marc Rousavy 3b0e39534e Forward String::length in RuntimeDecorator and WithRuntimeDecorator (#58936)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/58936

`IRuntime::length(const String&)` came in with "Add `String::length` API" (590396bd4 on static_h, D96030262), and that commit didn't touch `decorator.h`. Neither `RuntimeDecorator` nor `WithRuntimeDecorator` overrides it, so on a decorated runtime `length()` falls back to the default `utf16(str).size()` and never reaches the wrapped runtime.

It looks like an oversight. The same stack added `push`, `tryGetMutableBuffer`, `detached` and the TypedArray methods, and each of those commits added decorator overrides, including one for this method's overload `length(const TypedArray&)`. The `createError*` commit (https://github.com/facebook/hermes/issues/2203) and this one didn't.

For Hermes-backed decorators the value is already right, because Hermes' `utf16()` is exact, but every call copies the whole string instead of reading the length. Runtimes with a native `length()` and the default `utf16()` get wrong answers. React Native's `JSCRuntime` is one: built against the system JavaScriptCore and wrapped in a `RuntimeDecorator`, `'a\uD800b'` has length 1 instead of 3 and `'x\uDC00yz'` has 1 instead of 4. With this change both match the undecorated runtime. That setup lives outside this repo, so it isn't a test here.

`WithRuntimeDecorator` needs the override too. Otherwise it would inherit the plain forward and `length()` would skip `Around`, which it currently goes through via `utf16()`.

`TracingRuntime` no longer records an incidental `Utf16Record` when `length()` is called. That record only came from the `utf16()` fallback. I didn't add a record for `length()`: strings are immutable, and `TracingRuntime` already leaves pure queries like `size(Array)` untraced.

X-link: https://github.com/facebook/hermes/pull/2205

Test Plan:
Added `JSITest.DecoratorForwardsStringLength`. An inner decorator returns a sentinel from `length()` and counts `length()` and `utf16()` calls. The test checks that a `RuntimeDecorator` and a `WithRuntimeDecorator` over it both reach that `length()` without calling `utf16()`, and that `Around` runs once. It fails without the change (it gets 5 from the `utf16()` fallback) and passes with it. The full `APITests` binary passes (357 tests) in a Debug + ASan build, including the SynthTrace and TraceInterpreter tests.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed By: avp

Differential Revision: D123943189

Pulled By: lavenzg

fbshipit-source-id: 519fdde9f2ad46ce906567bfd1d94d787015915c
(cherry picked from commit be567d270c)
2026-10-26 13:36:38 +00:00
Tomek Zawadzki 9b24e0df01 Avoid fmod when rounding layout results to the pixel grid (#2041)
Summary:
copysign(x - trunc(x), x) is bit-identical to fmod(x, 1.0) for every
double but avoids the libm fmod loop, which is slow on Android's bionic.
roundValueToPixelGridDouble runs six times per node on every layout
pass.

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D125600548

fbshipit-source-id: 7866bfb8619f7a6ec63bf799821a8c2270340a57

Author set to the author of react/yoga#2041; the commit on main carries the Yoga sync account.

Conflict resolved for 0.88-stable: kept the branch's variable name `fractial` (renamed to `fractional` on main in #58712). The change itself is identical to bf8d8c9a7a.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit bf8d8c9a7a)
2026-10-26 12:43:55 +00:00
Gregory Moskaliuk bce6961a2b Skip the clear background attribute on iOS Text (#59207)
Summary:
`RCTNSTextAttributesFromTextAttributes` (`ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm`) builds the attributes TextKit draws each text fragment with.

**Current behavior.** It sets `NSBackgroundColorAttributeName` whenever `textAttributes.backgroundColor` is set or `opacity` is set. `TextAttributes::defaultTextAttributes()` sets `backgroundColor` to `clearColor()`, so every fragment of every `<Text>` gets a transparent background attribute, including text that never asked for a background. On every draw, `NSLayoutManager` then computes the rects of each run carrying that attribute and fills them with the clear color, which changes no pixels. In a Time Profiler trace of mounting 1000 labels on a device, this background pass was about a third of `-[RCTTextLayoutManager drawAttributedString:...]`.

**With this change.** The attribute is set only when the background color is set and is not `clearColor()`. A clear background draws nothing, so the pixels are the same, and TextKit skips the background pass for text without a background. Text with a visible background color keeps the attribute as before, including with `opacity`. A nested `<Text>` with `backgroundColor: 'transparent'` inside a parent with a background renders the same, since each fragment carries its own attributes. The other reader of the attribute, `processTruncatedAttributedText:` in `RCTTextLayoutManager`, already handles it being absent.

## Changelog:

[IOS] [CHANGED] - Text without a background color no longer draws a transparent background

Pull Request resolved: https://github.com/react/react-native/pull/59207

Test Plan:
- `node scripts/clang-format.js --check` on the changed file passes.
- RNTester built with `xcodebuild` in Release and run on a physical iPhone 15 Pro (iOS 26.6.1).
- **Same output.**
  - Screenshots of a list of 1000 labels in bordered cards, with shadow props and with `boxShadow`, are byte-identical in the list area with and without the change.
  - In the RNTester Text examples (25 screens of scrolling, including text with background colors, borders and nested text), static screens are byte-identical with and without the change once scroll positions are aligned. Where a screen landed a few points off, only the anti-aliased corners of rounded Views differ, by at most 5 levels, and the same screen captured at the same position is byte-identical. Screens with animated content differ between two runs without the change as well.
- **Measurement.** RNTester Playground mounting items in a `ScrollView`, each a `View` wrapping a `Text`, with three contents (plain, bordered card with shadow props, and the card with `boxShadow`). Timed: the total time in `-[RCTParagraphTextView drawRect:]` in the display pass after each mount, and the time from the end of the mount to the CoreAnimation commit, which contains that pass. The two arms are the same binary with the change switched by an environment variable. 20 items were mounted ten times per content per launch, in the order before, after, after, before. 1000 items were mounted five times per content per launch, in two series in opposite orders (before, after, after, before, then after, before, before, after), which gave the same numbers. The presses were driven by [Argent](https://github.com/software-mansion/argent) on the physical iPhone. iPhone 15 Pro, Release, medians:

| 20 labels, 62–63 mounts per arm | before | this PR | change |
|---|--:|--:|--:|
| text drawing per mount | 5.06 ms | 3.58 ms | −29% |
| end of mount to CoreAnimation commit | 4.4 ms | 3.4 ms | −23% |

| 1000 labels, 60 mounts per arm | before | this PR | change |
|---|--:|--:|--:|
| text drawing per mount | 58.1 ms | 38.2 ms | −34% |
| end of mount to CoreAnimation commit | 124.4 ms | 93.6 ms | −25% |

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed By: cipolleschi

Differential Revision: D126404689

Pulled By: javache

fbshipit-source-id: 03fe945bdaacc438497f945858b995c285310c69
(cherry picked from commit 0bd33261d1)
2026-10-26 12:43:49 +00:00
nishan (o^▽^o) 1177976e2b Fix flex shrink explosion when the shrink total is a positive float residual
Summary:
Fixes https://github.com/react/yoga/issues/2038
Fixes https://github.com/react/yoga/issues/1651
Closes https://github.com/react/yoga/issues/2039
Closes https://github.com/react/yoga/issues/1855

Thanks to sebholl for the analysis and the reproduction in https://github.com/react/yoga/issues/2038.

## Issue

When a flex line overflows, the first pass freezes the items that hit their minimum size and removes them from the shrink total. The second pass then divides the remaining free space by that total.

The total was computed by subtracting the frozen items flex shrink factors from the float total. When every item freezes, the total should become 0, but float subtraction leaves a small residual.

### Example

All items have `flexShrink: 1`:

```
row (width: 350, flexDirection: row)
├── A  width: 100.1  minWidth: 90
├── B  width: 200.3  minWidth: 190
└── C  width: 300.7  minWidth: 290
```

The items need 601.1 but the row is only 350, so they must shrink by 251.1. Each item would go below its `minWidth`, so the first pass freezes all three (at 90 / 190 / 290) and removes them from the shrink total. With no items left, the total should be 0. But in float, `-601.1 + 100.1 + 200.3 + 300.7 = 0.000061`.

That is above the `1e-6` guard added in https://github.com/react/yoga/issues/1974 (for https://github.com/react/yoga/issues/1665), so the second pass divides the remaining free space by it: `-220 / 0.000061 ≈ -3.6 million`. Instead of staying at their min, the items grow to about **361M / 722M / 1084M** (expected **90 / 190 / 290**).

### Solution

With non-negative `flexShrink`, every scaled shrink factor is ≤ 0, so a real total is never positive. A positive total can only be this float residual, and dividing by it is what makes the items explode. The second pass now treats a positive total like the near-zero case of the `1e-6` guard from https://github.com/react/yoga/issues/1974 and uses the existing fallback. Negative residuals (which the min clamp already handles) and all other layouts are unchanged. Fixing the fallback for `flexShrink < 1` (https://github.com/react/yoga/issues/931) is left for a separate PR.

#### Why not `inexactEquals` (|total| < 0.0001)?
The leftover grows with the size of the total. For example, 60 chips of about 100pt each in a 1000pt row give a total of about 6000, and the leftover is then often larger than 0.0001. In a test with rows like this, about half of them still exploded with `inexactEquals`. With the sign check, none did, because a real shrink total is never positive.

X-link: https://github.com/react/yoga/pull/2044

Reviewed By: javache

Differential Revision: D126038629

Pulled By: cortinico

fbshipit-source-id: dc1ec3370783e227ce4477bcd632ae5907034193
(cherry picked from commit 24a3be5f99)
2026-10-26 12:43:49 +00:00
nishan (o^▽^o) e00ad86620 Keep the measured pixel size of text nodes when rounding to the pixel grid (#2040)
Summary: When a text node's scaled size is a whole number of pixels, use that pixel count as its rounded size instead of the difference of its two rounded edges. The 0.0001 snap tolerance could snap one edge to a pixel and floor the other, which made the node one pixel smaller than its measured size and truncated its text.

Reviewed By: cortinico

Differential Revision: D125427541

Author set to the author of react/yoga#2040; the commit on main carries the Yoga sync account.

fbshipit-source-id: 4fdd9223120938b35c38fc75df1602cbbc01820a
(cherry picked from commit fd5392494f)
2026-10-26 12:43:48 +00:00
ybelakov c2a4a95b54 Round node dimensions in double so far-off nodes keep their full size (#2037)
Summary:
* Round node dimensions in double so far-off nodes keep their full size

A node's rounded width and height are the difference of its two rounded
absolute edges. roundValueToPixelGrid returns float, so that difference was
taken in float; far from the origin a float has fewer bits than a pixel, and
when the two edges fall on either side of a power of two they are quantized
differently. A measured text node spanning y = 2048 on a 3x screen came out
43.9998779 tall instead of 44, one float step short of the two lines it was
measured at, and the text renderer then dropped the last line.

Round in double and subtract before narrowing to float. The public
roundValueToPixelGrid keeps its signature.

* Cover both fractions on either side of 1024, 2048 and 4096 in the rounding test

On the previous rounding each of these came out off by a float step
(44.00006, 43.99994, 43.99988, 43.99988 and 43.99976); all are exactly 44
now.

* Remove comments

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D125427496

fbshipit-source-id: 4ba056bb164207d540032252633112358db80581

Author set to the author of react/yoga#2037; the commit on main carries the Yoga sync account.

Co-authored-by: nishan (o^▽^o) <nishanbende@gmail.com>
(cherry picked from commit 4de5b675b0)
2026-10-26 12:43:48 +00:00
Alex Hunt dd11eb80cf Tweak LogBox notifications for iPhone Duo, fix rail touches (#58958)
Summary:
Minimal fixes to the LogBox notification toasts for the iPhone Duo, where they stretch across the unfolded display and block the tab bar beside them when folded.

- Cap the toasts at 600pt wide and center them, so they no longer span the unfolded display edge to edge.
- **Fix**: Pass touches outside the toasts through to the app, so the folded Duo's rail tab bar beside them stays tappable.
- **Fix**: Raise the dismiss ×'s contrast from about 2.5:1 to about 7:1. Previously, it drew in the toast's own color on a mid-gray circle and read as **faint/invisible**; the icon is unchanged.
- **Tweak**: Round corners from 8 to 12px.

| Before | After |
|---|---|
| <img src="https://github.com/user-attachments/assets/612d33c1-8d93-4a47-8bd5-5d3c118fb5c4" width="400" /> | <img src="https://github.com/user-attachments/assets/ae436c7d-06b6-4f7f-a07c-5ee7cbe51aef" width="400" /> |

Changelog:
[General][Fixed] - **LogBox**: Fix bottom notification appearance/touch targets on iPhone Duo

Pull Request resolved: https://github.com/react/react-native/pull/58958

Test Plan:
```
yarn test packages/react-native/Libraries/LogBox
```

**iPhone Duo, folded**

| Before | Before, tab bar blocked | After |
|---|---|---|
| <img src=--sanitized--

Reviewed By: vzaidman

Differential Revision: D124115690

Pulled By: Abbondanzo

fbshipit-source-id: 0844b21f898d309eff50235147dc5f0bb8b9ca3e
(cherry picked from commit 88a8bd23e8)
2026-10-26 12:32:48 +00:00
mattijsf 22c950b534 Ignore stale image callbacks after an Image view is recycled on iOS (#58669)
Summary:
Fixes https://github.com/react/react-native/issues/58667.

On iOS with the new architecture, an `<Image>` can show the image of another `<Image>` that was unmounted just before. `RCTImageResponseObserverProxy` dispatches its callbacks to the main queue. `RCTImageComponentView` used one proxy for its whole lifetime, and `didReceiveImage` only checked that the view still had a state. When a view was recycled and handed to a new `<Image>` while a callback for the old request was still queued, that callback was applied to the new image. If the new source was cached it had already been applied synchronously on subscribe, so the late old image stayed on screen.

This change:

- creates a new `RCTImageResponseObserverProxy` for every subscription in `_setStateAndResubscribeImageResponseObserver`
- ignores image, progress and failure callbacks whose `observer` is not the current proxy (the `fromObserver:` argument was already passed but not used). For failures this also stops a stale error from clearing the new image.

The proxy's address identifies the subscription. The new proxy is allocated before the previous one is released, so two consecutive subscriptions never share an address. Reuse of an old address would need two resubscriptions while a callback from the first one is still queued.

## Changelog:

[IOS] [FIXED] - Image no longer shows the image of a previous source after its native view is recycled

Pull Request resolved: https://github.com/react/react-native/pull/58669

Test Plan:
Reproducer: https://github.com/mattijsf/rn-image-recycled-view-stale-image (React Native 0.87.1, also as a Snack: https://snack.expo.dev/mattijsf/image-recycle-stale-load-ios?platform=ios). It mounts 64 uncached remote images (red), replaces them with a cached one (green) as soon as the first red one has loaded, and counts a wrong image when the new image's `onLoad` reports the old image's size. A run is 50 rounds.

Release build on the iOS simulator (iPhone 17 Pro Max, iOS 26.5), React Native built from source (`RCT_USE_PREBUILT_RNCORE=0`), one run of 50 rounds each. The diff applies unchanged to 0.87.1.

| | rounds with a wrong image | wrong images |
| --- | --- | --- |
| 0.87.1 | 27 of 50 | 120 |
| 0.87.1 with this change | 0 of 50 | 0 |

With the change the red images still show up briefly before each swap, as intended, but none of them end up on a green tile.

Reviewed By: christophpurrer

Differential Revision: D121619393

Pulled By: javache

fbshipit-source-id: 78c29450bb25083667515c95f8c704d3b7db5eef
(cherry picked from commit 53bf98bf40)
2026-10-26 12:32:48 +00:00
Jakub Adamczyk 76e8459246 Fix Android text mis-measurement when using fontVariationSettings (#58320)
Summary:
`fontVariationSettings` (https://github.com/react/react-native/issues/57804, https://github.com/react/react-native/issues/57805) is applied with `Paint.setFontVariationSettings` after `Paint.setTypeface`. Android's `Paint.setFontVariationSettings` returns early when the requested settings string equals the value the paint already holds, and `Paint.setTypeface` does not clear that stored string. On the legacy variation path, the variation instance lives on the typeface, so once `setTypeface` replaces the typeface the axes are gone, but the paint still reports the old settings and the second `setFontVariationSettings` call is a no-op.

With a variable font whose default instance is lighter than the requested `wght`, Yoga receives regular-width metrics while semibold glyphs are drawn, so `numberOfLines={1}` text is ellipsized ("Get Start...") and wrapped text breaks in different places than it renders.

This change clears the paint's settings before re-applying them in `ReactTypefaceUtils.applyFontVariationSettings` and in `ReactEditText.maybeUpdateTypeface`, so the axes are always rebuilt on the current typeface. Paints without previous settings are unaffected.

## Changelog:

[ANDROID] [FIXED] - Fix text measured with the wrong width when `fontVariationSettings` are re-applied to a reused `Paint`

Pull Request resolved: https://github.com/react/react-native/pull/58320

Test Plan: Ran test suite, validated the fix in my patched react-native instance that backports variable fonts support.

Reviewed By: andrewdacenko

Differential Revision: D118791592

Pulled By: javache

fbshipit-source-id: 937e6bb2ceed937679abfb6ca192a74fd385b3eb
(cherry picked from commit 96518a8fb9)
2026-10-26 12:32:48 +00:00
Peter Abbondanzo a1a6bf46c0 Skip empty text decoration draws (#59050)
Summary:
Pull Request resolved: https://github.com/react/react-native/pull/59050

`drawSpannedDecoration` now skips zero-line layouts and empty or fully hidden spans before measuring or drawing. Add native regression coverage for the clamped ranges.

Changelog:
[Android][Fixed] - Skip empty and fully hidden text decoration ranges

Reviewed By: cortinico

Differential Revision: D125038370

fbshipit-source-id: 87bfafe019b261aa2ef9996f4700a633e28263f7
(cherry picked from commit dbd5b3b770)
2026-10-26 12:32:48 +00:00
Lazizbek Ergashev 711f2c83a0 fix(android): clamp text decoration offsets to truncated layout (#58366)
Summary:
On Android, a `Text` with `numberOfLines` can crash when a nested `Text` has `textDecorationLine: 'underline'` or `'line-through'` and the decorated span starts or ends past what the truncated layout actually rendered. `drawSpannedDecoration()` reads `start`/`end` from the full, untruncated `Spanned` text and passes them straight to `Layout.getPrimaryHorizontal()`, which throws `IndexOutOfBoundsException` once numberOfLines cuts the layout shorter than the span.

This clamps both offsets to the last position the truncated (and possibly tail-ellipsized) layout can actually resolve before using them, so a partially hidden span draws its decoration up to the visible boundary and a fully hidden span draws nothing, instead of crashing.

## Changelog:

[ANDROID] [FIXED] - Fix crash drawing text decoration (underline/strikethrough) when a nested Text's span extends past a numberOfLines-truncated layout

Pull Request resolved: https://github.com/react/react-native/pull/58366

Test Plan:
Added two regression tests in `TextDecorationStyleTest`: both build a single-line, tail-ellipsized `StaticLayout`. One checks clipping a span that starts visible and extends beyond the layout; the other checks the zero-length line for a fully hidden span.

The formatting/API-annotation correction leaves the production source, test bodies, and assertions unchanged. Exact parent test run: https://www.internalfb.com/intern/testinfra/testrun/20829148333669211.

Fixes https://github.com/react/react-native/issues/58356

Reviewed By: javache

Differential Revision: D125060226

Pulled By: Abbondanzo

fbshipit-source-id: 0ddf275086750e9fe82ceca385f2eb92a2a00dd9
(cherry picked from commit ca8504b1ca)
2026-10-26 12:32:48 +00:00
Christian Falch b6137a4e4b Compile React Native C/C++ at -O2 on iOS to match Android (#59226)
Summary:
iOS Release builds compile React Native's C, C++ and Objective-C code with `-Os` (optimize for size). React Native never sets `GCC_OPTIMIZATION_LEVEL`, so Xcode's default applies. Android compiles the same code with `-O2` (optimize for speed) in Release. Yoga even sets `-O2` explicitly ("prioritize speed", `ReactCommon/yoga/cmake/project-defaults.cmake`).

This PR sets `GCC_OPTIMIZATION_LEVEL = 2` for Release builds of React Native's own code on iOS, to match Android. Android also builds Yoga and glog at `-O2` in Debug builds, so this PR does the same on iOS. All other code keeps `-O0` in Debug. Hermes keeps its size-optimized `MinSizeRel` build, as on Android. Swift code is not affected.

In a layout benchmark on Apple Silicon, a Yoga layout takes 21–54% less time at `-O2` than at `-Os` in Release. In Debug it takes about 94% less time at `-O2` than at `-O0` (16–19 times faster). The stripped React binary grows by 6.2%.

After this PR, every library that both platforms compile uses the same optimization level: React Native core, Yoga, folly, glog, fmt, boost and double-conversion. Two differences stay out of scope: Android also uses link-time optimization, and Android turns off Yoga's assertions in Debug builds.

I found no commit that chose `-Os` for iOS on purpose. The earlier optimization decisions were all for Android: `c04ab921924` (2016, "Use -O3 to compile CSSLayout in open source … This is how we compile internally") and https://github.com/react/react-native/issues/37371 (2023, Yoga's reference CMake build at `-O2`).

The question came up in the community. A user profiling Bluesky found Yoga about 20% faster at `-O2` and layout 2–5% faster in the full app: https://github.com/bluesky-social/social-app/pull/12061. Their app-level workaround is https://github.com/expo/expo/pull/51770. An app-level setting cannot reach the prebuilt React Native frameworks, so the fix belongs here.

### What changes

| Build path | Change |
|---|---|
| Prebuilt `React.xcframework` (`packages/react-native/scripts/ios-prebuild/build.js`) | Adds `GCC_OPTIMIZATION_LEVEL=2` to the `xcodebuild` command for the Release flavor only. |
| Prebuilt `ReactNativeDependencies.xcframework` (`scripts/releases/ios-prebuild/build.js`) | Same, for folly, glog, fmt, boost, double-conversion, fast_float and SocketRocket. |
| CI cache (`.github/workflows/prebuild-ios-dependencies.yml`) | The slice and xcframework cache keys now include `scripts/releases/ios-prebuild/build.js`. Without this, CI reuses the cached `-Os` build. |
| Yoga in `React.xcframework` (`packages/react-native/Package.swift`) | The `yoga` target gets `-O2` in every configuration, as on Android (`ReactCommon/yoga/CMakeLists.txt`). |
| glog in `ReactNativeDependencies.xcframework` (`scripts/releases/ios-prebuild/configuration.js`) | glog gets `-O2` in every configuration, as on Android (`ReactAndroid/src/main/jni/third-party/glog/CMakeLists.txt`). |
| CocoaPods builds from source (`react_native_post_install`) | New step `set_optimization_level_for_react_native_pods`. It sets level 2 on Release-type configurations of React Native pods, and on every configuration of `Yoga` and `glog`. |
| SwiftPM codegen package (`packages/react-native/scripts/codegen/templates/Package.swift.spm-template`) | `ReactCodegen` and `ReactAppDependencyProvider` get `-O2` in Release through `unsafeFlags`, as the CocoaPods generated pods do. SwiftPM allows `unsafeFlags` here because the app always uses this package from a local path. |

The command-line setting applies to every configuration, so the prebuild scripts add it only when they build Release. The per-target `-O2` for Yoga and glog comes after the configuration's `-O0` on the compiler command line, so it wins in Debug.

In CocoaPods, a React Native pod is one of these:
- a local pod inside the `react-native` package
- one of React Native's third-party dependency pods (`RCT-Folly`, `glog`, `boost`, `DoubleConversion`, `fmt`, `fast_float`, `SocketRocket`)
- one of the generated pods `ReactCodegen` and `ReactAppDependencyProvider`

Community library pods, the app's own pods and `hermes-engine` do not change. Release-type configurations are found by `config.type == :release`, as `add_ndebug_flag_to_pods_in_release` already does, so custom configurations such as "Staging" are included.

An app that wants the old behaviour can set `GCC_OPTIMIZATION_LEVEL` back to `s` in its own `post_install` after `react_native_post_install`.

### Benchmark: layout speed

Yoga built twice from this branch with Apple clang 21.0.0 (`-std=c++20 -DNDEBUG -arch arm64`); only the optimization level differs. The benchmark harness is the same object file in both builds. Every iteration forces a full relayout (root width alternates 390/391). There were 10 runs of each build, alternating. Both builds produce identical layout results.

Machine: Apple M4 Max, macOS 27.0.1. This is a Mac, not an iPhone, and the trees are synthetic.

| Scenario | `-Os` (µs per layout, median) | `-O2` (µs per layout, median) | Time reduction |
|---|---|---|---|
| Feed: 500 rows, each with an avatar, 3 measured text nodes and 4 buttons | 2,879 | 2,261 | 21% |
| Deep: 15 levels, mixed row/column, padding, margin, percent widths | 1,098 | 805 | 27% |
| Grid: 1,000 wrapped items with `aspectRatio` | 1,018 | 472 | 54% |

"Time reduction" = 1 − median(`-O2`) / median(`-Os`). The spread between the fastest and slowest of the 10 runs was 3–11%.

Debug builds, same harness, built without `NDEBUG` so Yoga's assertions stay on, as in an iOS Debug build. Median of 3 alternating runs:

| Scenario | `-O0` (µs per layout) | `-O2` (µs per layout) | Time reduction |
|---|---|---|---|
| Feed | 36,350 | 2,310 | 94% (15.7× faster) |
| Deep | 15,184 | 816 | 95% (18.6× faster) |
| Grid | 8,190 | 486 | 94% (16.9× faster) |

### Benchmark: binary size

Release, `ios-arm64` device slice. Sizes are uncompressed; App Store download size will differ.

| Binary | `-Os` (bytes) | `-O2` (bytes) | Difference |
|---|---|---|---|
| `React.framework/React`, stripped (`strip -x`) | 6,154,912 | 6,537,576 | +382,664 (+6.2%) |
| `React.framework/React`, `__TEXT` segment | 4,931,584 | 5,324,800 | +393,216 (+8.0%) |
| `ReactNativeDependencies.framework`, stripped | 778,240 | 873,296 | +95,056 (+12.2%) |
| Yoga only, `__text` section | 77,140 | 112,188 | +35,048 (+45%) |

The unstripped React binary gets *smaller* (10,785,672 → 10,335,408 bytes). More inlining at `-O2` leaves about 4,950 fewer symbols, so the link-edit data shrinks more than the code grows. The stripped size is the relevant number.

If only Yoga were moved to `-O2`, the stripped React binary would grow by 32,776 bytes (+0.53%).

## Changelog:

[IOS] [CHANGED] - Compile React Native's C/C++/Objective-C code with `-O2` instead of `-Os` in Release, and Yoga and glog with `-O2` in all builds, to match Android

Pull Request resolved: https://github.com/react/react-native/pull/59226

Test Plan:
**Unit tests.** New Jest tests check that the Release command has `GCC_OPTIMIZATION_LEVEL=2`, the Debug command does not, and the rest of each command is unchanged. They failed before the change and pass after it.

```
yarn jest packages/react-native/scripts/ios-prebuild/__tests__/build-test.js scripts/releases/ios-prebuild/__tests__/build-test.js
Tests: 8 passed, 8 total
```

A new Jest test checks that the SwiftPM codegen template gives `ReactCodegen` and `ReactAppDependencyProvider` the Release-only `-O2` flag in both `cSettings` and `cxxSettings`, and that `ReactAppHeaders` does not get it. It failed before the change and passes after it.

```
yarn jest packages/react-native/scripts/spm/__tests__/codegen-template-optimization-test.js
Tests: 5 passed, 5 total
```

All tests in `packages/react-native/scripts/ios-prebuild` and `scripts/releases`: 24 suites, 196 tests passed. All tests in `packages/react-native/scripts/spm`: 23 suites, 1060 tests passed. ESLint, Prettier and Flow report no errors on the changed files.

**Prebuilt frameworks.** I built `React.xcframework` (`node scripts/ios-prebuild --setup --build --compose --platforms ios --flavor <Debug|Release>`) and `ReactNativeDependencies.xcframework` (`node scripts/releases/prepare-ios-prebuilds.js --setup --build --compose --platforms ios --configuration <Debug|Release>`), then read the last `-O` flag in each target's compiler argument file:

| Build | React Native code | Yoga | glog | Other dependencies |
|---|---|---|---|---|
| Release, before this PR | `-Os` | `-Os` | `-Os` | `-Os` |
| Release, with this PR | `-O2` | `-O2` | `-O2` | `-O2` |
| Debug, with this PR | `-O0` | `-O2` | `-O2` | `-O0` |

**CocoaPods.** `RCT_USE_PREBUILT_RNCORE=0 RCT_USE_RN_DEP=0 bundle exec pod install` in `packages/rn-tester`, then read `Pods.xcodeproj`:
- `Yoga` and `glog`: `GCC_OPTIMIZATION_LEVEL = 2` in Debug and Release.
- Other React Native targets (`React-*`, `RCT-Folly`, `ReactCodegen`, `SocketRocket`, …): 2 in Release, unset in Debug.
- RNTester's own pods (`ScreenshotManager`, `MyNativeView`, `NativeCxxModuleExample`, …) and the app targets: unset in both configurations.

**SwiftPM.** In `private/helloworld`: `node ../../packages/react-native/cli.js spm add --deintegrate --version nightly`, then `xcodebuild -configuration Release -sdk iphonesimulator build`. The build succeeded, and Xcode accepted `unsafeFlags` in the generated package. The `-O` flags in each target's compiler argument file:
- `ReactCodegen` and `ReactAppDependencyProvider`, Release: `-Os`, then `-O2`. The last flag wins.
- The app target and `ReactAppHeaders`, Release: `-Os` only.
- `ReactCodegen` and `ReactAppDependencyProvider`, Debug: `-O0` only.

**Not tested:**
- `pod install` in prebuilt mode. No prebuilt frameworks exist for the development version, so it fell back to source. In prebuilt mode the React pods contain only binaries, so the setting has no effect there.
- Layout speed on a physical iPhone, and in RNTester.
- The Ruby CocoaPods unit tests, which are not run in CI.

Reviewed By: andrewdacenko

Differential Revision: D126452701

Pulled By: cipolleschi

fbshipit-source-id: d1b4296200a37300f0d6134cc8f922b4c3754c61

(cherry picked from commit 60c817e925)

Conflict resolution for 0.88-stable: added only the -O2 flags, without the main-only Yoga excludedPaths and codegen RN_ALLOW_FRAMEWORKS define.

(cherry picked from commit f407034625)
2026-10-26 12:32:47 +00:00
Christian Falch 9dbb7e5e03 Add regression tests for the iOS SwiftPM tooling (#59217)
Summary:
Recent fixes to the iOS SwiftPM tooling (`scripts/spm`) all fixed bugs that CI did not catch. Adopters found them first. Each fix added a test for its own bug only. The bugs fall into a few classes: output that changes when nothing changed, generated names that collide or do not resolve, values that are hard-coded instead of read from the app, machine-specific paths in files that users commit, and malformed files that Xcode tolerates.

This PR adds two test-only tools that look for each class in general. They run in the existing Linux Jest job (`test_js`). No production code changes.

1. **Invariant checker** (`spm-invariants.js`, not a test file itself). It reads the files that the tooling generates and returns a list of violations:
   - no machine paths (temp dir, `$HOME`, absolute build-setting values) in `project.pbxproj`, `.xcscheme`, or `.spm-injected.json`;
   - the scheme parses as XML, and the pre-action script keeps its line breaks;
   - in every generated `Package.swift`, target and product names are unique (also case-insensitive) and valid C99 identifiers, and every dependency resolves, including products of local `.package(path:)` dependencies;
   - every generated or scaffolded manifest uses the app's iOS deployment target; the codegen manifest, whose template fixes `.iOS(.v15)`, must not be above it;
   - `project.pbxproj` is balanced, every referenced object ID is defined, and the frameworks in `.spm-injected.json` match the project.

   Each rule also fails when the file or field it checks is missing, so a check cannot pass by finding nothing.

2. **Lifecycle test** (`spm-lifecycle-test.js` + `spm-fixture-app.js`). It builds a fake app on disk (deployment target 16.4), fake prebuilt artifacts for two React Native versions, and four fake libraries: one with its own `Package.swift`, one podspec-only library with `module_name` different from its npm name, one scoped `acme/…` package, and one autolinking plugin with a flavored framework. It then runs `scaffold → add → sync → sync → update (same version) → update (next version) → deinit` through `setup-apple-spm.js`, and runs the checker after each step. It also asserts:
   - a second sync changes no byte and replaces no `libs/` entry;
   - the build-time stale check reacts to the right changes and ignores files that Xcode writes;
   - a plugin framework mismatch makes sync exit with code 2;
   - `update` to the same version and `deinit` restore the project and scheme byte for byte.

   Network access, `plutil`, `otool`, codegen and `pod` are mocked, so the test runs offline on Linux.

## Changelog:

[INTERNAL] [ADDED] - Add regression tests for the iOS SwiftPM tooling

Pull Request resolved: https://github.com/react/react-native/pull/59217

Test Plan:
```
yarn jest --no-cache -i packages/react-native/scripts/spm/__tests__
```
Result: 24 suites, 1124 tests, all passed, about 23 s (on main at dd9b6c52ab). The two new suites take about 4 s.

Each earlier fix was undone one at a time with `git show <sha> -- ':!**/__tests__/**' | git apply -R`, and the new tests failed each time:

| Fix reverted | New tests failing |
|---|---|
| https://github.com/react/react-native/issues/58826 (scheme pre-action newlines) | 9 |
| https://github.com/react/react-native/issues/58292 (absolute `HERMES_CLI_PATH` in pbxproj) | 9 |
| https://github.com/react/react-native/issues/58597 (`libs/` rewritten on every sync) | 2 |
| https://github.com/react/react-native/issues/58828 (watched path absent at add time) | 1 |

`yarn eslint` and `prettier --check` on the new files: clean.

Not run: Linux locally. The `test_js` job on this PR is the first Linux run.

Reviewed By: cortinico

Differential Revision: D126304581

Pulled By: cipolleschi

fbshipit-source-id: c1bacf9ef2c6955a262cac0053491d69535375e9
(cherry picked from commit fba55e24c9)
2026-10-26 12:32:47 +00:00
Christian Falch 84e60bc30b SwiftPM: declare ReactAppHeaders in the codegen placeholder package (#59293)
Summary:
A SwiftPM app can get stuck when setup skips codegen. Setup skips codegen when you pass `--skipCodegen`, when codegen fails ("Continuing anyway"), or when the codegen script is missing. In each case `spm add` / `spm update` writes a placeholder `build/generated/ios/Package.swift`, which the "Sync SPM Autolinking" hook replaces during the build.

The placeholder declared only `ReactCodegen` and `ReactAppDependencyProvider`. Every autolinked or scaffolded library manifest also depends on `ReactAppHeaders` from that package. So Xcode fails package resolution:

```
product 'ReactAppHeaders' required by package 'reactnativesafeareacontext' target 'ReactNativeSafeAreaContext' not found in package 'React-GeneratedCode'.
```

Xcode resolves packages before the scheme pre-action and the build phases, so neither hook runs, and every later build fails the same way. The only way out is to run setup again with codegen, and the error does not say so.

This change makes the placeholder declare `ReactAppHeaders` (every entry of `REACT_CODEGEN_PRODUCTS`) too. `SPM_PRODUCT_PACKAGES` is unchanged, because it also decides which products the app target links, and the app must not link `ReactAppHeaders`.

Known limit, not changed here: after this fix the first build still fails once, because the hook generates the library's codegen headers during that build, after the package graph is resolved (for example `'react/renderer/components/safeareacontext/Props.h' file not found`). The next build succeeds with no other change.

## Changelog:

[IOS] [FIXED] - SwiftPM: a project set up with skipped codegen no longer fails package resolution on `ReactAppHeaders`

Pull Request resolved: https://github.com/react/react-native/pull/59293

Test Plan:
Unit tests: two new tests for `ensureStubPackages` in `generate-spm-xcodeproj-test.js`. One checks that the placeholder declares each codegen product exactly once. One checks that an existing `Package.swift` is not changed.

```
yarn jest --no-cache -i packages/react-native/scripts/spm/__tests__/generate-spm-xcodeproj-test.js
```

- Without the source change: 1 failed (`ReactAppHeaders` declared 0 times).
- With the source change: 66 passed, 66 total.
- ESLint (`--max-warnings 0`) and Prettier pass on both files.

Fresh app (Xcode 27.1): `0.89.0-nightly-20261021-c7429b0e9` + `react-native-safe-area-context` 5.10.1, `npx react-native spm add --deintegrate --skipCodegen`, then `xcodebuild -resolvePackageDependencies` and `xcodebuild build`:

- Without the fix: resolution fails with the error above; the build stops at resolution (exit 74) and no hook runs.
- With the fix applied to the app's copy of the script: resolution passes; the first build runs the sync hook, which replaces the placeholder, and then fails on the missing library codegen headers (exit 65); the second build succeeds.

Not run: full `yarn flow-check` (a scoped Flow check showed no errors in the changed files).

Reviewed By: andrewdacenko

Differential Revision: D126658850

Pulled By: cipolleschi

fbshipit-source-id: 0ef10c5180f5932cfd761b16418e9a368401550b
(cherry picked from commit e3aa9a1e19)
2026-10-26 12:32:47 +00:00
Christian Falch a25ec465e4 Stop reading podspec header search paths during SwiftPM sync (#59365)
Summary:
In the SwiftPM pipeline, every sync reads the podspec of each npm dependency to collect its `HEADER_SEARCH_PATHS`. (That can even start a `pod ipc spec` process for each dependency), and the result is never used.

This change removes the read and the code that carried its result:

- `extractPodspecHeaderSearchPaths` and its call in `autolinkingDepToSpmTarget` (`generate-spm-autolinking.js`)
- the `headerSearchPaths` field on `SpmTarget` and `SynthPackageSpec` (`spm-types.js`)
- the `root/` prefix step in `main()` and the `.headerSearchPath(...)` output in `generateSynthPackageSwift`

The podspec reader (`read-podspec.js`) and the scaffolder (`scaffold-package-swift.js`) still use header search paths. They do not change.

This PR does not depend on other open PRs.

## Changelog:

[INTERNAL] [REMOVED] - Stop reading unused podspec header search paths during SwiftPM sync

Pull Request resolved: https://github.com/react/react-native/pull/59365

Test Plan:
- New test in `generate-spm-autolinking-test.js`: an npm dependency whose podspec sets `HEADER_SEARCH_PATHS` must not cause a call to the podspec reader. Before the change it failed with `Expected number of calls: 0, Received number of calls: 1`. After the change it passes.
- `node_modules/.bin/jest --no-cache -i packages/react-native/scripts/spm`: 23 of 23 suites and 1129 of 1129 tests pass.
- Generated output for RNTester, before and after, with `node packages/react-native/scripts/spm/generate-spm-autolinking.js --app-root packages/rn-tester --react-native-root packages/react-native --autolinking-json <file> --output <dir>`:
  - With RNTester's npm dependencies, both runs stop with the same missing-manifest error and write no files.
  - With only RNTester's app-local modules, both runs write the same 7 `Package.swift` files. `diff -r` finds no differences.
- ESLint and Prettier pass on the changed files. Flow finds no errors in them. I did not run a full `yarn flow-check`, because it fails locally on unrelated vendored files.

Reviewed By: andrewdacenko

Differential Revision: D126936104

Pulled By: cipolleschi

fbshipit-source-id: 178520a0fe5037aa646c20d2b9ffafd178b4888f

(cherry picked from commit 4bba13d419)

Conflict resolution for 0.88-stable: kept 0.88's REACT_CXX_CONFIG_DEFINES for cxxSettings instead of main's reactCxxDefines(spec.cxxApiDefines), which is not on 0.88.

(cherry picked from commit abe1c5f041)
2026-10-26 12:32:47 +00:00
Christian Falch cd89e98949 SwiftPM: move injected build settings and build scripts out of project.pbxproj (#58834)
Port of 6a2c7c2734 (#58834) to 0.88-stable. This is not a plain cherry-pick: the commit on main also moves the C++ stable API opt-ins from #59043 into the generated xcconfig, and #59043 is not on 0.88-stable. This port is the reviewed version of #58834 from before it was rebased onto #59043. Everything else is the same as the commit on main.

Summary:
`npx react-native spm add` and `spm update` edit the app's `project.pbxproj`. Today they write React Native's build settings and the full text of two build scripts into that file. Some of these values change with every React Native version. So a routine `spm update` gives a `project.pbxproj` diff, and teams get merge conflicts in a file that is hard to read.

This PR moves those values out of `project.pbxproj` into files that React Native generates next to it:

- `ReactNativeSPM/ReactNativeSPM.xcconfig` holds the build settings. Each app build configuration uses it as its base configuration.
- `ReactNativeSPM/Scripts/sync-autolinking.sh` and `ReactNativeSPM/Scripts/embed-flavored-frameworks.sh` hold the script bodies. The build phases in `project.pbxproj` only run these files.

The result: when a version bump does not change the set of packages or plugin frameworks, `spm update` gives no `project.pbxproj` diff. The changes go to the generated files.

Commit the `ReactNativeSPM/` directory with the project. Xcode reads these files before the build starts, so they must exist on a fresh clone. They are not in the ignored `build/` directory for that reason.

`project.pbxproj` still holds the package references, the product dependencies, and the build phases. Xcode has no other place for them.

`REACT_NATIVE_PATH` also changes. It is now `$(SRCROOT)/<path>` through `node_modules/react-native`. Before, with pnpm, it could be the resolved `.pnpm/react-native@<version>_<hash>` path. That path is specific to one machine, and it was committed.

### Limits

- The "no diff" result applies only when packages are referenced by local path. In remote mode, the package version in `project.pbxproj` still changes on each bump.
- When you add or remove a plugin framework, the input and output paths of the embed phase in `project.pbxproj` still change. Xcode requires these paths in the project file.
- `spm add` and `spm update` now refuse a target in two new cases, with a message that tells you what to do:
  - A configuration already uses a different xcconfig file as its base, and that file does not `#include` the generated one. React Native does not edit xcconfig files that it does not own. The message gives the exact `#include` line to add to your file. After you add it, `spm` accepts the configuration and leaves its base unchanged.
  - The target sets a list setting that the generated file also sets, without `$(inherited)`. The target value would hide the React Native value. The message names the settings to fix.
- Configuration names that contain spaces or `]` are not escaped in the `[config=<name>]` conditions.
- A configuration that you add in Xcode after `spm update` (for example, a copy of Release named "Staging") gets the release flavor until the next `spm update` adds its own condition.

### Existing apps

No manual migration is necessary. On the next `spm update`, React Native removes the build settings that it wrote before (it records them in its marker file), then writes the xcconfig file.

### Details for reviewers

- `generate-spm-xcodeproj.js`:
  - `generateReactNativeXcconfig()` writes the settings. Flavor-specific settings (`RN_SPM_FLAVOR`, `SWIFT_ACTIVE_COMPILATION_CONDITIONS`) use Xcode's `[config=<name>]` conditions, with the real configuration names from the project. One file serves all configurations.
  - `mergeReactBuildSettings()` is removed.
  - An unconditioned `RN_SPM_FLAVOR = release` comes before the `[config=<name>]` lines, as the fallback for configurations that the file does not list.
  - `generatedScriptWrapper()` writes the stable build-phase text. If the script file is missing, the build fails with a message to run `npx react-native spm update`. The embed script is an input path of its phase, so Xcode runs the phase again when the script changes.
  - `planInjection()` follows the `#include` chain of a configuration's base xcconfig. Each path resolves from the folder of the file that contains it, and a cycle stops the walk. The configurations that include the generated file are recorded in the marker as `xcconfig.includedByConfigUuids`.
  - The CocoaPods template sets `REACT_NATIVE_PATH` relative to `${PODS_ROOT}`. A target value outranks an xcconfig value, so injection removes that one value. Deinit does not put it back, because the value resolves to an empty path when CocoaPods is not used.
  - `linkedReactNativeRoot()` finds the `node_modules/react-native` link that resolves to the real React Native directory, to build the stable path.
  - `injectSpmIntoPbxproj()` now takes `{fromAppRoot, fromSrcRoot}` as its third argument.
  - Deinit removes the base-configuration references, the file reference, and the generated files. If a configuration uses a different xcconfig that may include the generated one, deinit keeps the generated file and logs why.
- `xcconfig-files.js` (new): xcconfig path resolution and `#include` parsing, moved out of `ios-deployment-target.js` so both files share it. `ios-deployment-target.js` behaves as before.
- `spm-pbxproj.js`: `ensureScalarField()` takes an `{after}` option, to put `baseConfigurationReference` at the correct position.

## Changelog:

[IOS] [CHANGED] - SwiftPM: `spm add` and `spm update` write React Native's build settings to `ReactNativeSPM/ReactNativeSPM.xcconfig` and its build scripts to `ReactNativeSPM/Scripts/`, so a version bump no longer changes `project.pbxproj`. A configuration that uses its own xcconfig must now `#include` the generated file, and a target setting that hides React Native's value must add `$(inherited)`. `spm` prints the exact fix in both cases.

Pull Request resolved: https://github.com/react/react-native/pull/58834

Test Plan:
```
yarn jest --no-cache -i packages/react-native/scripts/spm
```

Result on this 0.88-stable port branch: 22 suites and 1099 tests pass (0.88-stable before the 5 ports: 21 suites, 1005 tests). The new tests failed before the change.

New tests:

- `inject-spm-xcodeproj-test.js`: a version bump (new React Native path and new framework slice data) gives a byte-identical `project.pbxproj`. Other tests check that each configuration uses the generated xcconfig, that a `${PODS_ROOT}`-based `REACT_NATIVE_PATH` is removed, that a user xcconfig is accepted when its `#include` chain reaches the generated file and refused otherwise, that the refusal gives the exact `#include` line, and that the embed script is an input of its phase.
- `remove-spm-injection-test.js`: a list setting without `$(inherited)` is refused. Settings from an older injection move into the xcconfig on the next update. Deinit removes the xcconfig reference and the generated files, keeps a base configuration that the user changed, and keeps the generated xcconfig while a user xcconfig may include it. A user xcconfig that includes the generated one survives add → sync → deinit unchanged. pnpm layouts give `$(SRCROOT)/…/node_modules/react-native`. A nearer `node_modules/react-native` that is a different install is skipped.
- `generate-spm-xcodeproj-test.js` and `spm-pbxproj-test.js`: the xcconfig content and the `{after}` option.

Also run:

- `flow focus-check` (flow-bin 0.331.0, as 0.88-stable pins) on the changed files: no errors in them.
- `prettier --check` and `eslint --max-warnings 0` on the changed files: no problems.
- CI on this PR: `test_ios_spm_helloworld`, `test_ios_spm_newapp` and `test_ios_spm_rntester` (Debug and Release) run `spm add` and a full `xcodebuild` with the generated xcconfig. Not run locally.

Not tested:

- An Xcode project in a subdirectory of the app root (`--xcodeproj`). The generated files are written relative to the app root. This case was also not supported before this change.

Ported from commit 6a2c7c2734, without the #59043 changes.

(cherry picked from commit 27150439fb)
2026-10-26 12:32:47 +00:00
Christian Falch 990243c044 docs(swiftpm): correct SwiftPM docs to match current scripts (#58968)
Summary:
Several statements in the SwiftPM docs no longer match the scripts on `main`. This PR corrects them. It changes docs only.

- `scripts/spm/__docs__`: CLI options, the three causes of exit code 2, what `sync` does and when it re-runs, which command writes each file, the header products a hand-written library depends on, and remote mode. Adds a table of environment variables.
- `scripts/ios-prebuild/__docs__`: the SwiftPM statements about where dependency and Hermes headers go.

Where the code has a known gap, the docs describe the current behavior. Examples: `npx react-native spm` does not forward `--configCommand`, and `spm scaffold` also changes the `.xcodeproj`.

A second commit simplifies the same docs: it removes repeated statements and splits long sentences. No facts change. The header resolution details move to `spm-header-paths-contract.md`.

## Changelog:

[INTERNAL] [CHANGED] - Correct SwiftPM docs to match current scripts

Pull Request resolved: https://github.com/react/react-native/pull/58968

Test Plan:
- `npx prettier --check packages/react-native/scripts/{spm,ios-prebuild}/__docs__/*.md`: all files pass.
- Each changed statement was checked against the code on `main`. Relative links and anchors in changed lines resolve.

Reviewed By: christophpurrer

Differential Revision: D125209110

Pulled By: cipolleschi

fbshipit-source-id: faa09373ec67ed6c4f0f560428c0996716cdae5c
(cherry picked from commit 649c946516)
(cherry picked from commit 0f95088438)
2026-10-26 12:32:47 +00:00
Christian Falch 1648ee03b8 Fail SwiftPM sync when plugin frameworks and the Xcode project disagree (#58827)
Summary:
An autolinking plugin, such as Expo, can provide precompiled frameworks. The build-time `sync` reads the list of these frameworks from the plugin. `npx react-native spm add` and `spm update` write a second list: the frameworks that the Xcode project links. When the two lists differ, the build fails at the link step with "no such file … plugins/<pkg>.xcframework" or "no such module". That error does not say what is wrong or what to run.

This happens, for example, when a module is precompiled after the last `spm update`, or when a teammate commits a project that links a module this machine does not provide.

This PR makes `sync` compare the two lists before the build continues. For each framework that differs, it prints an Xcode `error:` line that names the framework and what to do, and it exits with code 2. Existing projects already stop the build on exit code 2.

How it works:

- `spm add` and `spm update` record the linked frameworks in `.spm-injected.json`, next to the project. The check reads them there. For a marker from an older version, the check reads the embed phase of `project.pbxproj`, as before.
- `.spm-injected.json` is now a sync input. A pull that changes what the project links starts a sync on the next build. `project.pbxproj` is not a sync input, because Xcode rewrites it on many IDE edits.
- On a mismatch, `sync` saves the error lines in `build/generated/autolinking/.spm-plugin-mismatch` and refreshes its stamp. Later builds print the saved errors and stop without running the full sync again. When any sync input changes, the next build runs the sync and the check again. When the check passes, `sync` deletes the file.
- The team must precompile the same set of frameworks on every machine, because the committed project is the contract. So the messages say:
  - Project links a framework that no plugin provides: precompile it, then run `npx react-native spm sync`. Running `spm update` instead removes it from the committed project for the whole team.
  - A plugin provides a framework that the project does not link: run `npx react-native spm update` to add it for the whole team.
- The help text of `npx react-native spm` now lists `sync`, because the error tells users to run it.
- `sync` still never writes `project.pbxproj`. Only `spm add` and `spm update` change what the project links.
- React Native's own frameworks are not compared.
- The check uses Xcode's `PROJECT_FILE_PATH` to find the project being built.

This PR is independent of https://github.com/react/react-native/issues/58828. They can land in either order. Both change the generated sync check, so the second one to land needs a rebase.

## Changelog:

[IOS] [ADDED] - SwiftPM: the build stops with a clear error when precompiled plugin frameworks and the Xcode project disagree, and the error says what to run.

Pull Request resolved: https://github.com/react/react-native/pull/58827

Test Plan:
```
yarn jest --no-cache -i packages/react-native/scripts/spm/__tests__/
```

Result: 22 suites and 1046 tests pass. The new tests failed before the change. One exception: the test that a newer `project.pbxproj` alone does not start a sync passed at once, because it guards against a regression.

- `plugin-framework-mismatch-test.js` uses a real injected project. It runs each case twice: with the list recorded in the marker, and with an older marker that has no list. It covers a framework that is missing in either list, a renamed framework, matching lists, a name with a space, a project that is not injected or has no embed phase, a missing manifest, and two injected projects. It also checks that running `spm add` or `spm update` twice gives the same `project.pbxproj`, and the warning when an older marker and a missing manifest make the check skip one direction.
- `sync-spm-autolinking-test.js` checks that a mismatch saves the errors and refreshes the stamp, that a passing check deletes the saved errors, the recovery after a precompile, and the exit codes of the script's direct entry point.
- `generate-spm-xcodeproj-test.js` runs the generated sync check under `/bin/bash`. It checks that a later build prints the saved errors without a sync, that a changed sync input runs the sync again, that a newer `.spm-injected.json` starts a sync, and that a newer `project.pbxproj` alone does not.

Not tested:

- The exit-code-2 mapping in `setup-apple-spm.js`. `main()` has no test seam. The change is one `instanceof` check.
- A full Xcode build with a precompiled plugin. The order (the sync phase runs before the link step) comes from the code and from `spm-scripts.md`.

Reviewed By: cortinico

Differential Revision: D125208952

Pulled By: cipolleschi

fbshipit-source-id: c7727e0e77932c5260237183bbd14ae7195819e3
(cherry picked from commit a920e5db46)
(cherry picked from commit 50c6e9726d)
2026-10-26 12:32:47 +00:00
Christian Falch 6da65e822a Re-sync SwiftPM autolinking when a watched path appears (#58828)
Summary:
The SwiftPM build-time sync runs only when its stamp is older than one of the files it watches. A watched path that did not exist at the last sync was dropped from the watch list. So when that path appeared later, the sync did not run.

Examples:

- A plugin watches its precompiled-module folder. On a fresh clone, that folder does not exist yet, so later precompiles never trigger a sync.
- A dependency has no root `Package.swift` or `.react-native/` folder. When one appears later, for example after `npx react-native spm scaffold`, the dependency is detected differently, but the sync does not run.

This PR writes missing watch paths to a new file, `.spm-sync-watch-absent`. The stamp is stale when one of those paths now exists. The missing paths do not go to `.spm-sync-watch-paths`, because projects from older versions treat a missing path in that file as stale and would sync on every build. Those projects get this fix after running `npx react-native spm update` once.

The paths that can go to `.spm-sync-watch-absent`:

- a plugin `watchPaths` entry that does not exist yet
- the root `Package.swift` and `.react-native/` of each dependency, when they do not exist

The docs now tell plugins to list their precompiled-module folder in `watchPaths`, but only a folder that the Xcode build does not write to.

This PR does not watch `project.pbxproj`. Xcode rewrites that file on many edits in the IDE, so watching it would run a full sync after each edit. https://github.com/react/react-native/issues/58827 makes `.spm-injected.json` a watched file instead. Only `spm add` and `spm update` change that file.

This PR is independent of https://github.com/react/react-native/issues/58827. They can land in either order. Both change the generated sync check, so the second one to land needs a rebase.

## Changelog:

[IOS] [FIXED] - SwiftPM: the build-time sync now runs again when a watched path that did not exist at the last sync appears.

Pull Request resolved: https://github.com/react/react-native/pull/58828

Test Plan:
```
yarn jest --no-cache -i packages/react-native/scripts/spm/__tests__/
```

Result: 21 suites and 1010 tests pass.

- `generate-spm-autolinking-test.js`:
  - A missing watch path goes to `.spm-sync-watch-absent` only. This test failed before the change.
  - A dependency without a root `Package.swift` or `.react-native/` lists both paths as absent. The first version of this PR already did this, so the test passed at once. Removing the two paths from the code makes it fail.
  - `project.pbxproj` is not watched. This test failed before the change.
- `generate-spm-xcodeproj-test.js`: runs the shipped bash check under `/bin/bash`. The stamp is stale only when a path listed as absent now exists.

Reviewed By: andrewdacenko

Differential Revision: D125206241

Pulled By: cipolleschi

fbshipit-source-id: 2cb530615941b15adb27f8fcc4699812538e9f3d
(cherry picked from commit c89f4120ac)
(cherry picked from commit 8c5d3879a2)
2026-10-26 12:32:46 +00:00
Christian Falch 90ba1173d9 Encode line breaks in SwiftPM scheme pre-action scriptText (#58826)
Summary:
The SwiftPM setup adds a "Sync SPM Autolinking" pre-action to the app's Xcode scheme. The pre-action never ran its sync step.

The script is many lines long. `escapeXmlAttribute` wrote it into the `scriptText` XML attribute with raw line breaks. An XML parser replaces each raw line break in an attribute value with a space (XML 1.0 §3.3.3). So Xcode read the script as one line. The second line of the script is a `#` comment, so everything after `set -euo pipefail` became part of that comment.

This PR makes two changes in `packages/react-native/scripts/spm/generate-spm-xcodeproj.js`:

- `escapeXmlAttribute` now also encodes `\r`, `\n` and `\t` as `&https://github.com/react/react-native/issues/13;`, `&https://github.com/react/react-native/issues/10;` and `&https://github.com/react/react-native/issues/9;`. Xcode itself writes the script this way.
- `deinit` deletes a scheme that RN created only when the scheme is still unchanged. This check now ignores the value of the script. Without this change, a scheme that an older version wrote with raw line breaks would no longer match, and `deinit` would leave it on disk. The XML decoder had no callers left after this change, so this PR removes it.

Existing projects get the fixed script when the user runs `npx react-native spm update` once. The build-time `sync` does not rewrite the scheme.

## Changelog:

[IOS] [FIXED] - SwiftPM: keep line breaks in the scheme pre-action script so that the "Sync SPM Autolinking" pre-action runs. Run `npx react-native spm update` once to rewrite an existing scheme.

Pull Request resolved: https://github.com/react/react-native/pull/58826

Test Plan:
New tests:

- `generate-spm-xcodeproj-test.js`: parses the generated scheme with `xmldom/xmldom` and checks that the script keeps its line breaks and tabs. A second test checks that a refresh of an older scheme with raw line breaks writes `&https://github.com/react/react-native/issues/10;`.
- `remove-spm-injection-test.js`: checks that `deinit` still deletes an RN-created scheme whose script has raw line breaks.

```
yarn jest --no-cache -i packages/react-native/scripts/spm/__tests__/generate-spm-xcodeproj-test.js packages/react-native/scripts/spm/__tests__/remove-spm-injection-test.js
```

- Before the fix: 2 failed, 124 passed (the two `generate-spm-xcodeproj` tests).
- With only the encoding change: the new `deinit` test and 4 existing `deinit` tests failed.
- With both changes: 2 suites passed, 126 tests passed.

ESLint and Prettier pass on the changed files. `flow check-contents` reports no errors for `generate-spm-xcodeproj.js`.

I did not build an app in Xcode for this PR. An Expo app had the problem: when the line breaks in its scheme were changed to `&https://github.com/react/react-native/issues/10;` by hand, the pre-action ran.

Reviewed By: christophpurrer

Differential Revision: D123382914

Pulled By: cipolleschi

fbshipit-source-id: 0c51cb7c6fe7a66567602d813a13381f6bf3704f
(cherry picked from commit b8df948fd4)
(cherry picked from commit 1d69b9084d)
2026-10-26 12:32:46 +00:00
React Native Bot 99d4ed3985 [LOCAL] Bump Podfile.lock 2026-10-15 14:01:32 +00:00
React Native Bot 5c35c82cf7 Release 0.88.0
#publish-packages-to-npm&latest
2026-10-15 11:38:19 +00:00
React Native Bot 410d9b5b6d [LOCAL] Bump Podfile.lock 2026-10-14 16:43:44 +00:00
React Native Bot 1a72139b30 Release 0.88.0-rc.6
#publish-packages-to-npm&next
2026-10-14 14:54:05 +00:00
Cedric van Putten 536c008de0 fix(react-native): add missing AssetRegistry TypeScript types (#58964)
Summary:
https://github.com/react/react-native/issues/57369 moved the AssetRegistry into the public API of React Native starting from `0.87`. Unfortunately, it seems that the TypeScript types were not updated to include this API, resulting in type issues when trying to use:

```ts
import { AssetRegistry, type AssetDestPathResolver, type PackagerAsset } from 'react-native'
```

This PR fixes the typing issues for `0.88`.

The [Flow types were updated correctly](https://github.com/react/react-native/blob/2d913c7292088a7bc4482a6febb2ee4903d6f32f/packages/react-native/index.js.flow#L282-L286) in `0.87-rc.0`.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[GENERAL] [FIXED] Add missing TypeScript types for public `AssetRegistry` API

Pull Request resolved: https://github.com/react/react-native/pull/58964

Test Plan:
- Prepare any TypeScript project with React Native
- Run type checks for:
    `import { AssetRegistry, type AssetDestPathResolver, type PackagerAsset } from 'react-native'`
- Should succeed

Reviewed By: Abbondanzo

Differential Revision: D125060242

Pulled By: fabriziocucci

fbshipit-source-id: 4efadb3647afcac43ecd83472a88d9fb02882905
(cherry picked from commit b8ec87e457)
2026-10-14 08:54:12 +01:00
React Native Bot 749c6e7c6f [LOCAL] Bump Podfile.lock 2026-10-12 21:53:51 +00:00
React Native Bot a3249a2e43 Release 0.88.0-rc.5
#publish-packages-to-npm&next
2026-10-12 20:22:35 +00:00
React Native Bot aa78eebfec [LOCAL] Bump Podfile.lock 2026-10-06 22:41:11 +00:00
React Native Bot 62e60c3521 Release 0.88.0-rc.4
#publish-packages-to-npm&next
2026-10-05 17:21:13 +00:00
Mathieu Acthernoene ee4bd403d4 Make generated props and style types augmentable (#58168)
Summary:
react-native-web and Nativewind extend React Native's types with module augmentation. https://github.com/react/react-native/issues/58062 made the props and style types interfaces, which cleared the duplicate identifier errors. Two things still can't be extended.

**Styles:** `ViewStyle` is an interface derived from `____ViewStyle_Internal`, but `ViewProps['style']` reads the base, so augmenting `ViewStyle` doesn't reach it:

```ts
declare module 'react-native' {
  interface ViewStyle { transitionDuration?: string }
}

<View style={{ transitionDuration: '1s' }} />;             // error
StyleSheet.create({ box: { transitionDuration: '1s' } });  // error
```

`____ViewStyle_Internal` is now named `ViewStyle`, and the same for Text and Image. `StyleSheet` re-exports each name unchanged, so the interface and the base are one symbol.

**Props written as inline object literals:** The transform copies them into the interface body, where a second declaration is a merge conflict rather than an override, so the augmentation is silently ignored. Eleven of the 24 annotated types are affected. Each now moves its inline members into a private `<Name>Core` alias, so they reach the interface through the extends clause and are inherited, like everything from `ViewProps` already was:

```ts
// before
declare interface KeyboardAvoidingViewProps extends Readonly<ViewProps> {
  readonly enabled?: boolean
}

// after
declare interface KeyboardAvoidingViewProps extends Readonly<
  ViewProps & KeyboardAvoidingViewPropsCore
> {}
```

That costs 11 new names in the API snapshot, one per affected type. `PressableProps` set the precedent with `PressableBaseProps`.

`ImagePropsBase` and `ImageBackgroundProps` declare members that shadow keys of the type they spread, and a Flow spread of an optional property unions the two types instead of replacing the member, so those keys get an explicit `Omit`.

Caveat: an augmented member has to be assignable to the inherited one. Adding a key is clean and narrowing works, but widening raises `TS2430` on the declaration file, which `skipLibCheck: true` silences.

[GENERAL] [CHANGED] - Allow module augmentation to extend generated props and style types

Pull Request resolved: https://github.com/react/react-native/pull/58168

Test Plan:
`yarn build-types`: all 24 annotated types now emit an empty interface body. `ViewStyle`, `TextStyle` and `ImageStyle` are unchanged; the props types gain the 11 `<Name>Core` aliases.

Compiled augmentations with `skipLibCheck: false`. Styles: the two lines above pass here and report `TS2353` on `main`. Props: adding a key and narrowing an existing one on each of the 11 types passes here and reports `TS2717` on `main`.

`yarn flow-check`, `yarn test-generated-typescript`, `yarn format-check` and `yarn lint`: clean, apart from 3 Flow errors in `packages/react-native-codegen/lib` already on `main`. `yarn jest packages/react-native/Libraries packages/react-native/src scripts/js-api`: 632 tests pass, no snapshot changed.

Reviewed By: christophpurrer

Differential Revision: D117876097

Pulled By: cortinico

fbshipit-source-id: c0797f14d95a01662930f7158738ea79e1bf1a30
(cherry picked from commit 447ccd1ddb)
2026-10-05 15:57:00 +01:00
Fabrizio Cucci 7822b9cce2 Properly enable Pressable after disabled prop reset (#58799)
Summary:
JSI drops `undefined` keys, so reseting `disabled` from `true` to `undefined` on Touchables/Pressables never runs `setEnabled(true)`

There is props diffing feature flag that fixes this, which is off by default

Also added safety check against explicit `null` & reset on recycling

Fixes https://github.com/react/react-native/issues/56777 and supersedes https://github.com/react/react-native/issues/58795

## Changelog:

[ANDROID] [FIXED] - Properly enable Pressable after `disabled` prop resets from `true`

Pull Request resolved: https://github.com/react/react-native/pull/58799

Test Plan:
Added BaseViewManagerTest as well as videos of testing it on Pressable:

https://github.com/user-attachments/assets/e9a7dcd2-46d5-4cdc-88a3-728bff22e76b

https://github.com/user-attachments/assets/043150ae-64f2-47c9-b13c-abfec5b61747

Reviewed By: javache

Differential Revision: D122872380

Pulled By: zeyap

fbshipit-source-id: f3f1cad378f36f006bbb6c7f3f2e4f9aa8e61541
(cherry picked from commit 357b6998c4)
2026-10-05 14:42:14 +01:00
React Native Bot 600715184a [LOCAL] Bump Podfile.lock 2026-09-28 11:28:04 +00:00
React Native Bot 0782c61fe6 Release 0.88.0-rc.3
#publish-packages-to-npm&next
2026-09-28 09:11:17 +00:00
Fabrizio Cucci 993be7d6c6 Bump Hermes to 260318099.0.4
Picks up two fixes released in hermes-v260318099.0.4:

- Avoid reserve() in ConsecutiveStringStorage. Lazy compilation appends to
  the string storage on every newly compiled function, and reserve() on
  libc++ sizes to exactly the requested capacity rather than growing
  geometrically, so repeated appends were quadratic.
- Re-land of the VariableScope rescan optimization.

See https://github.com/reactwg/react-native-releases/issues/1430
2026-09-27 12:28:32 +01:00
Christian Falch 7fdfc4ebf3 Repair stale staged headers in the iOS prebuild (#58596)
Summary:
The iOS prebuild (`node scripts/ios-prebuild`) stages React Native's headers into `packages/react-native/.build/headers` as hard links, and skipped any target that already existed.

When changing the original source files, these hard links can become stale and errors like this can occur:

```
Libraries/LinkingIOS/RCTLinkingManager.mm:91:7: error: use of undeclared identifier 'RCTIsSceneDelegateApp'
```

This is a problem that contributors will see - not regular users, but the fix helps with strange error messages.

## Changelog:

[INTERNAL] [FIXED] - Repair stale staged headers in the iOS prebuild instead of compiling against a previous checkout's copies

Pull Request resolved: https://github.com/react/react-native/pull/58596

Test Plan:
✅ New unit tests, 16 cases in `packages/react-native/scripts/ios-prebuild/__tests__/setup-test.js`, using real temporary directories rather than an `fs` mock, since the defect is about inodes.

End to end on an Xcode 27 checkout:

- Replaced a staged header with a copy, so it kept the same contents but a different inode. `node scripts/ios-prebuild -s -f Debug` restored it to the source inode and logged `Linked React/Base → .build/headers/React`. The previous code skipped it.
- Ran setup a second time with nothing changed: no file was relinked, and nothing was logged.
- Confirmed the three colliding targets still resolve to the same source as before the change, by inode.
- `node scripts/ios-prebuild -b -f Debug -p ios-simulator` → `** BUILD SUCCEEDED **`.

Reviewed By: cipolleschi

Differential Revision: D120740409

Pulled By: shwanton

fbshipit-source-id: 41c1eb112c3395d6c7158d7151be7fdd92a21cef
(cherry picked from commit b935e74ad5)
2026-09-24 15:23:36 +01:00
Christian Falch 9465ef76f7 Stop re-creating library package roots on every sync (#58597)
Summary:
Building an app in Xcode fails when it autolinks a library that ships its own `Package.swift`, with one error per such library:

```
Missing package product 'reactnativeskia_ReactNativeSkia.ReactNativeSkia'
Missing package product 'reactnativesafeareacontext_ReactNativeSafeAreaContext.ReactNativeSafeAreaContext'
```

The same project builds fine from the command line. Two problems combine.

**The sync destroys package roots Xcode has already loaded.** Autolinking writes one symlink per self-managed library into `build/generated/autolinking/libs/<Name>`, and Xcode treats each as a local Swift package root. The generator deleted that whole directory and recreated it on every run, even when the generated output was byte-for-byte identical. Measured on a real app, across one no-op sync: the `libs/` inode changed from 1913513750 to 1913930645, `libs/ReactNativeSkia` from 1913513937 to 1913930649, while the generated `Package.swift` kept the same MD5. Recreating a package root that Xcode has already resolved is what produces the error above.

**Xcode's own bookkeeping made the sync run every time.** The "Sync SPM Autolinking" build phase re-syncs when a watched input looks newer than its stamp, and it checked each library's whole directory with `find <dir> -newer <stamp>`. Xcode writes its per-user scheme state inside that directory, at `<lib>/.swiftpm/xcode/xcuserdata/<user>.xcuserdatad/xcschemes/xcschememanagement.plist`. So Xcode's own write marked the next build stale, which triggered the destructive re-sync, which broke that build. `xcodebuild` does not write that file, which is why command-line builds were never affected.

This change makes the `libs/` tree idempotent — unchanged entries keep their inode, and entries that are no longer autolinked are pruned instead of wiped — and makes the staleness check skip `.swiftpm`.

### How to verify

In an app that autolinks a library shipping its own `Package.swift`, build in Xcode twice in a row. Both builds should succeed. Before this change the second build fails with `Missing package product`.

## Changelog:
[IOS][FIXED] - Stop SwiftPM autolinking from recreating library package roots on every sync, which broke Xcode builds of apps using libraries that ship their own Package.swift

Pull Request resolved: https://github.com/react/react-native/pull/58597

Test Plan:
**Unit tests.** `yarn test packages/react-native/scripts/spm` — 21 suites, 1009 tests pass.

New tests, written and seen failing before the fix:

- Two consecutive generation runs over an unchanged self-managed dependency keep both the `libs/` inode and each entry's inode. Failed before the fix with the same inode churn measured on the real app.
- A dependency removed between two runs leaves no symlink under `libs/`.
- The emitted staleness snippet is extracted from the generated script and executed under `/bin/bash -c` with `set -euo pipefail` against a temporary tree. A write under `.swiftpm/` is ignored; a real source change is still detected.

**Real app.** A React Native 0.87.1 app on Xcode 27 autolinking `shopify/react-native-skia` and `react-native-safe-area-context`, both self-managed. Before: `xcodebuild` succeeded, Xcode failed in about 5 seconds with the two errors above, on nearly every build.

**Not run:** the full CI matrix, and no Android-side check — this touches iOS SwiftPM tooling only.

## Scope

Deliberately minimal.

One case still re-syncs: the first time Xcode creates `.swiftpm` inside a library, that bumps the library directory's own mtime, so the build after a fresh checkout reports stale once per library. That is harmless now that the sync is idempotent.

One related item is left alone: the aggregate `Package.swift` is still rewritten on every sync even when its content is unchanged, which bumps its mtime and can make Xcode re-resolve. That is wasteful but not destructive, and it is no longer reached on an ordinary IDE build now that `.swiftpm` writes do not mark the sync stale.

Reviewed By: cipolleschi

Differential Revision: D120740029

Pulled By: shwanton

fbshipit-source-id: 3783d4cee4791ab13517d8f0dcac71f752cb7c1b
(cherry picked from commit 97cc934dc7)
2026-09-24 15:23:27 +01:00
Bao Nguyen 6532c25d24 Expose ReactNativeFeatureFlags through react-private-interface (#57940)
Summary:
Fixes https://github.com/react/react-native/issues/57933.

`react-native/virtualized-lists` is published separately and imported `ReactNativeFeatureFlags` through `react-native/src/private/featureflags/ReactNativeFeatureFlags`, which is not listed in `react-native`'s `"exports"`. Metro therefore warned and fell back to file-based resolution whenever an app rendered a virtualized list.

Thanks huntie for the patch and the direction — this PR now applies it instead of the original approach:

- `ReactNativeFeatureFlags` is exposed on the existing private package boundary, `react-native/react-private-interface` (both the runtime getter and the `.js.flow` re-export);
- `VirtualizedList.js` and `VirtualizeUtils.js` import it from there.

No new `src/private/*` subpath is exported, and the feature-flag singleton is unchanged.

Per your review, the `scripts/monorepo-tests/__tests__/check-packages-test.js` and `scripts/shared/monorepoUtils.js` changes have been dropped — the PR is now just the patch above. Happy to look at enabling `react-native/no-deep-imports` on `virtualized-lists` as a follow-up if that's wanted.

`VirtualizeUtils.js` is included alongside `VirtualizedList.js` because it carried the same runtime deep import. The remaining occurrences are out of scope: the four in `react-native/jest-preset` are all `import type` and are erased before resolution, and the one in `VirtualizeUtils-test.js` is not shipped (`virtualized-lists` excludes `**/__tests__/**` from `files`).

## Changelog:

[GENERAL] [FIXED] - Fix the Metro package-exports warning caused by `react-native/virtualized-lists` importing an unexported React Native subpath.

Pull Request resolved: https://github.com/react/react-native/pull/57940

Test Plan:
No new test is added. The existing `virtualized-lists` suites already cover this route, because `VirtualizeUtils`/`VirtualizedList` read the flags at runtime through the new boundary.

Counterfactual — dropping only the `ReactNativeFeatureFlags` getter and its `import typeof` from `react-private-interface.js`, keeping the two `virtualized-lists` imports:

```text
TypeError: Cannot read properties of undefined (reading 'fixVirtualizeListCollapseWindowSize')

      182 |     let lastWillAddMore;
      183 |
    > 184 |     if (ReactNativeFeatureFlags.fixVirtualizeListCollapseWindowSize()) {
          |                                ^

      at computeWindowedRenderLimits (packages/virtualized-lists/Lists/VirtualizeUtils.js:184:32)
      at Object.<anonymous> (packages/virtualized-lists/Lists/__tests__/VirtualizeUtils-test.js:261:47)

Test Suites: 2 failed, 6 passed, 8 total
Tests:       20 failed, 1 skipped, 151 passed, 172 total
```

Restoring the getter makes it green again.

```text
$ yarn jest packages/virtualized-lists scripts/monorepo-tests packages/react-native/Libraries/ReactPrivate --runInBand
Test Suites: 9 passed, 9 total
Tests:       1 skipped, 176 passed, 177 total
Snapshots:   69 passed, 69 total

$ yarn flow-check
Found 0 errors

$ yarn lint
$ eslint --max-warnings 0 .
Done in 10.23s.
```

Reviewed By: javache

Differential Revision: D119164284

Pulled By: cortinico

fbshipit-source-id: 1e8ae3b85ae7fb28c55f207f887a97aad85b563c
(cherry picked from commit a506ed66cc)
2026-09-24 15:23:18 +01:00
Oskar Pawica e1988679c7 fix(android): bump androidx.collection to 1.4.4 to avoid MutableIntObjectMap corruption in SurfaceMountingManager (#58389)
Summary:
since https://github.com/react/react-native/issues/56646 the view registry is a `MutableIntObjectMap`; `androidx.collection` 1.4.0 to 1.4.2 corrupt `ScatterMap` and its primitive variants after remove-heavy sequences, fixed in 1.4.3 (https://issuetracker.google.com/issues/352560465). Apps resolve 1.4.0 or 1.4.2 and lose registry entries; RN then drops mount instructions and can leave stale views.

Fixes https://github.com/react/react-native/issues/58388.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

`[ANDROID] [FIXED] - Bump androidx.collection to 1.4.4 to fix view registry entries getting lost in SurfaceMountingManager`

Pull Request resolved: https://github.com/react/react-native/pull/58389

Test Plan:
Reproducer: https://github.com/pawicao/rn-android-view-registry-corruption
- RN 0.87.1 app resolving androidx.collection 1.4.2: 91 `Unable to find viewState` soft exceptions on 45 tags over two 40-round runs on a Pixel 9a, and a stale view left on screen.
- Same screen with androidx.collection pinned to 1.4.4: none over 120 rounds.

Reviewed By: cortinico

Differential Revision: D119149754

Pulled By: javache

fbshipit-source-id: afb13330bac575218a07a030bb1bcd5bf7e00824
(cherry picked from commit d6a5f159c6)
2026-09-24 15:23:08 +01:00
React Native Bot 62f0e0b54a [LOCAL] Bump Podfile.lock 2026-09-21 18:05:20 +00:00
React Native Bot 215169c51b Release 0.88.0-rc.2
#publish-packages-to-npm&next
2026-09-21 16:15:27 +00:00
Fabrizio Cucci 070af03ab3 Revert "Align TurboModule EventEmitter payload types across platforms (#58063)"
This reverts commit ab2ea649e6.
2026-09-21 14:42:15 +01:00