Skip to content

[0.88] Keep the iOS renderer scheduler alive through instance shutdown - #60550

Open
gabrieldonadel wants to merge 1 commit into
react:0.88-stablefrom
gabrieldonadel:@gabrieldonadel/0.88-pick-1568
Open

gabrieldonadel wants to merge 1 commit into
react:0.88-stablefrom
gabrieldonadel:@gabrieldonadel/0.88-pick-1568

Conversation

@gabrieldonadel

Copy link
Copy Markdown
Collaborator

Summary:

Backport of #59754 (bfea95fb4cc) to 0.88-stable, for pick request reactwg/react-native-releases#1568.

It fixes an iOS crash on a normal bridgeless reload (#59721, related #58601): a queued view command could reach a destroyed scheduler delegate. Every expo-updates reloadAsync() goes through this reload, and the crash is in the prebuilt React.framework.

The pick sits on #59145 (88d296713ca), which landed on 0.88-stable as 9c043dc11b0 through reactwg/react-native-releases#1582. With it, the commit applies to RCTInstance.mm, RCTScheduler, RCTSurfacePresenter, the podspec and three API snapshots without changes. Two conflicts were resolved by hand:

  • RNTesterPods.xcodeproj/project.pbxproj: kept the branch's lines and added only the four RCTInstanceInvalidationTests.mm entries. RCTTurboModuleStringConversionTests and RCTDevLoadingViewTests are not on 0.88, so their lines stay out.
  • ReactAppleFrameworksCxx.api: the snapshot does not exist on 0.88, so its change is dropped.

Changelog:

[IOS] [FIXED] - Prevent a queued view command from accessing a destroyed scheduler delegate during a normal bridgeless reload

Test Plan:

  • git cherry-pick -x keeps the original author.
  • plutil -lint passes on the resolved project.pbxproj.
  • The imports of the new RCTInstanceInvalidationTests.mm exist on 0.88-stable.
  • Not built locally. This PR is open so CI can build and run the RNTester unit tests, including RCTInstanceInvalidationTests.

Fixes react#59721.

During a normal bridgeless reload, `RCTInstance::invalidate` suspends the surface presenter before JS-thread cleanup runs. Suspension can destroy the renderer scheduler and its delegate proxy while the current JS task still has rendering updates capturing the proxy by raw pointer.

Retain the scheduler through that cleanup, and clear its Objective-C delegate after stopping surfaces. Before dispatching cleanup, permanently remove its layout-animation run-loop observer on main. Scheduler destruction then stays in the same JS cleanup block as runtime destruction, with the scheduler released first. This prevents both an observer callout racing teardown and queued JSI handles outliving the runtime. It adds no per-rendering-callback guard, synchronous main wait, or JS-to-main-to-JS destruction round trip.

Add three native lifecycle tests, the required CocoaPods Yoga header dependency for the scheduler import, and regenerated Apple API snapshots.

[IOS] [FIXED] - Prevent a queued view command from accessing a destroyed scheduler delegate during a normal bridgeless reload

Used the issue's public `Nezz/expo-repro` branch `repro/ReloadSchedulerCrash` (React Native 0.88.1), Xcode 27.1, and a dedicated iOS 27.1 iPhone Duo simulator.

- Initial reproduction: unmodified prebuilt crashed in 20/20 reloads; unmodified source crashed in 10/10. An actual EXC_BAD_ACCESS report contained `Scheduler::uiManagerDidDispatchCommand` and `RuntimeScheduler_Modern::updateRendering` on the JS thread.
- Final observer-detachment fix: 20/20 normal reloads acknowledged after removing all diagnostics, with no crashes or timeouts.
- Final observer-detachment fix: 20/20 instrumented reloads during a five-second layout animation acknowledged, with no crashes or timeouts. All 20 processes recorded real animation ticks, observer removal on main, scheduler destruction on JS, then runtime teardown. No ticks occurred after observer removal.
- After removing the diagnostics and rebuilding, another 5/5 animated reloads acknowledged with no crashes or timeouts.
- Three native lifecycle tests pass in a clean build without diagnostics. They exercise real instance invalidation/presenter suspension with scheduler and JS-thread-manager collaborators replaced, covering observer removal on main, no callbacks while JS cleanup is pending, scheduler retention/release, and invalidation without a scheduler. Runtime/JSI behavior is covered by the app trials, not by these probes alone.
- All 12 API snapshot validations pass with Doxygen 1.16.1; clang-format 21.1.2, Ruby podspec syntax, and `git diff --check` pass.

An unpublished intermediate approach that released the whole scheduler on main after JS cleanup crashed in 1/20 animated trials while destroying queued JSI handles. The final fix instead detaches only the observer on main and preserves scheduler-before-runtime destruction in one JS cleanup block.

Validation stages the production changes into the report's source-built 0.88.1 fixture; it is not a complete checkout-HEAD build or full RNTester suite. The reporter's iOS 26.5 environment, physical devices, and Release builds were not tested. This addresses normal off-JS-thread bridgeless reload, not a new policy for inline JS invalidation, standalone presenter suspension, nested main run loops, repeated invalidation, the legacy bridge, or the separate shared-animation backend.

Rebased onto main `25d63d471a91cf9c2141bbe8dab6802eb73c2567`. Both commits applied without conflicts, and `git range-diff` confirms unchanged patches.

All 12 API snapshots pass with Doxygen 1.16.1. Changed native sources pass clang-format 21.1.2, the podspec passes Ruby syntax checking, and diff checks pass. A fresh source build of the isolated React Native 0.88.1 fixture passes all three native lifecycle tests using the rebased test file and matching invalidation, observer-stop, and presenter-suspension methods.

The earlier app reload trials remain prior evidence. Fresh runtime validation covers the three native lifecycle tests in that fixture, with scheduler and JS-thread-manager test probes. Checkout-head RNTester and device/Release execution remain outside this validation.

Differential Revision: D129319362

Pull Request resolved: react#59754

(cherry picked from commit bfea95f)
Signed-off-by: Gabriel Donadel <donadeldev@gmail.com>
@gabrieldonadel
gabrieldonadel force-pushed the @gabrieldonadel/0.88-pick-1568 branch from fc3f5c8 to b828604 Compare December 5, 2026 14:39

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants