Skip to content

[iOS] Fix bad access when decorating runtime - #4187

Merged
m-bert merged 4 commits into
mainfrom
@jpiasecki/fix-runtime-bad-access
May 21, 2026
Merged

[iOS] Fix bad access when decorating runtime#4187
m-bert merged 4 commits into
mainfrom
@jpiasecki/fix-runtime-bad-access

Conversation

@j-piasecki

Copy link
Copy Markdown
Member

Description

After #4179 createGestureHandler is no longer synchronous - it's batched and scheduled asynchronously. This behavior change caused the runtime decoration to fail with bad access errors. This PR restores the previous synchronous flow of UI runtime decoration. The main difference is doing it eagerly on startup instead of lazily.

Test plan

Run the iOS app; it should not crash.

Copilot AI review requested due to automatic review settings May 21, 2026 13:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR restores a synchronous/eager path for decorating the Reanimated UI runtime bindings after createGestureHandler became asynchronously scheduled (PR #4179), addressing iOS “bad access” crashes during runtime decoration.

Changes:

  • Replaces setReanimatedAvailable(...) with a synchronous installUIRuntimeBindings(): boolean TurboModule API (JS + native).
  • Updates iOS/Android native modules to expose/install UI runtime bindings on demand (with internal caching via *_uiRuntimeDecorated).
  • Triggers UI runtime binding installation during Reanimated initialization (and makes it a no-op on web).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/react-native-gesture-handler/src/v3/NativeProxy.web.ts Switches proxy API to installUIRuntimeBindings() on web.
packages/react-native-gesture-handler/src/v3/NativeProxy.ts Switches proxy API to installUIRuntimeBindings() for native platforms.
packages/react-native-gesture-handler/src/specs/NativeRNGestureHandlerModule.ts Updates TurboModule spec: replaces setReanimatedAvailable with installUIRuntimeBindings(): boolean.
packages/react-native-gesture-handler/src/RNGestureHandlerModule.web.ts Implements installUIRuntimeBindings() as a web no-op returning true.
packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts Installs UI runtime bindings during Reanimated init; introduces worklets initialization step.
packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm Moves decoration behind exported installUIRuntimeBindings and renames internal decorator helper.
packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt Exposes installUIRuntimeBindings() and removes lazy decoration tied to handler creation.
Comments suppressed due to low confidence (1)

packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts:92

  • Worklets?.scheduleOnUI(() => ...) will still throw if scheduleOnUI is missing/non-callable (optional chaining here only guards Worklets itself). To avoid startup crashes, guard the call (e.g., Worklets?.scheduleOnUI?.(...) or a typeof check), and keep runtime binding installation working even when worklets don’t expose this API.
  // Make sure worklets are initialized before attemting to install UI runtime bindings
  Worklets?.scheduleOnUI(() => {
    'worklet';
  });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts Outdated
Comment thread packages/react-native-gesture-handler/src/v3/NativeProxy.ts
@j-piasecki
j-piasecki marked this pull request as ready for review May 21, 2026 13:18
@j-piasecki
j-piasecki requested a review from m-bert May 21, 2026 13:18
@m-bert
m-bert merged commit 3846335 into main May 21, 2026
9 checks passed
@m-bert
m-bert deleted the @jpiasecki/fix-runtime-bad-access branch May 21, 2026 13:54
@migueldaipre

migueldaipre commented May 25, 2026

Copy link
Copy Markdown

Hi everyone, sorry to bump this thread, but after updating to v3.0.0-beta.5, I'm getting the following error on iOS:

gesture-handler-error

Rolling back to v3.0.0-beta.4 works fine. I could set up a minimal repro if necessary.

cc @j-piasecki @m-bert

@m-bert

m-bert commented May 25, 2026

Copy link
Copy Markdown
Collaborator

Hi @migueldaipre!

I could set up a minimal repro if necessary.

That would be great. You can open new issue, then it will be easier to track.

Also, what is the first error message? The screens shows second one and maybe on the first there's something that would help us.

@j-piasecki

Copy link
Copy Markdown
Member Author

As a quick smoke test, can you try a clean rebuild of the app? That method has been added to the native module in beta.5, so it's possible that it's due to some caching.

@migueldaipre

migueldaipre commented May 26, 2026

Copy link
Copy Markdown

Hey everyone, sorry, it was a false alarm. It was probably just a cache issue, as @j-piasecki pointed out. Thank you for your time.

cc @m-bert

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.

5 participants