Skip to content

fix(ios): send the first regions event without experimental_flushSync - #46

Open
maksim-atria wants to merge 1 commit into
appandflow:mainfrom
maksim-atria:fix/ios-first-event-no-flush-sync
Open

maksim-atria wants to merge 1 commit into
appandflow:mainfrom
maksim-atria:fix/ios-first-event-no-flush-sync

Conversation

@maksim-atria

Copy link
Copy Markdown

Fixes #45.

On iOS the first regionsChange event was sent with experimental_flushSync. That makes the main thread wait for the JS runtime. If JS calls a native function that uses dispatch_sync to the main queue at that moment, the two threads wait on each other and the app freezes. Every iPhone hits that flush once per provider mount, not only the Duo, because the first layout always counts as a change. #45 has the stacks.

This sends the first event as a regular discrete event, like later changes but without the unique-event replacement. useReservedRegionsReady() still becomes true with the first measurement, one beat later than before. The README and the platforms page already say readiness is not a first-frame guarantee. I updated both to say iOS no longer requests synchronous delivery. Android is unchanged.

Verification

  • An app on React Native 0.88.1 (New Architecture), iOS 27.0 simulator, iPhone 18 Pro. A test component remounted a fresh provider every few milliseconds during launch and did a sync main-thread native read in each render. With 0.2.0, 10 of 10 cold starts froze with the deadlock stacks. With this change, 10 of 10 reached the first screen. Same JS bundle, only ReservedRegionsView.mm changed.
  • Not checked on the iPhone Duo or in this repo's example app. I didn't build the example.
  • oxfmt --check passes on the changed docs.

Known limitation

On the Duo, the first regions may now reach JS one beat after the first frame, so a layout that waits for readiness can show one frame later.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

iOS: first regionsChange flushSync can deadlock the app on cold start

1 participant