Skip to content

refactor: replace makeMutable with createShareable - #4406

Merged
tjzel merged 6 commits into
mainfrom
@tjzel/drop-in-worklets
Aug 10, 2026
Merged

refactor: replace makeMutable with createShareable#4406
tjzel merged 6 commits into
mainfrom
@tjzel/drop-in-worklets

Conversation

@tjzel

@tjzel tjzel commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Description

Replaces makeMutable with createShareable.

Test plan

🚀

Copilot AI review requested due to automatic review settings August 7, 2026 13:18
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 259a1a95-e967-4110-b81c-047b5f0e648f

📥 Commits

Reviewing files that changed from the base of the PR and between 8ac28ff and c625511.

📒 Files selected for processing (1)
  • packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.web.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.web.ts

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility between gesture handling, Reanimated, and Worklets.
    • Enhanced gesture event processing and cleanup on the UI runtime.
    • Added graceful fallback when required runtime capabilities are unavailable.
    • Improved reliability of UI runtime setup and error handling.
    • Ensured web builds avoid unsupported native runtime binding behavior.
    • Improved behavior when optional animation runtime features are not installed or cannot be initialized.

Walkthrough

The wrapper loads Worklets independently from Reanimated and conditionally installs UI runtime bindings. Event handlers lazily create shareable update maps when the required runtime capabilities are available.

Changes

Worklets event handler integration

Layer / File(s) Summary
Typed Worklets loading and runtime setup
packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts, packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.ts, packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.web.ts, packages/react-native-gesture-handler/src/__tests__/RuntimeBindings.test.ts
The wrapper defines typed Worklets and Reanimated contracts, loads both modules independently, and installs UI runtime bindings only when Worklets is available. Native setup queues installation and clears the runtime holder after completion. The obsolete test is removed.
Shareable event map creation
packages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.ts, packages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.web.ts, packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts
Event handlers lazily create update maps through Worklets when runtime capabilities are available. The web implementation returns an empty shareable host. Cleanup uses the new shareable-map type.

Sequence Diagram(s)

sequenceDiagram
  participant EventHandler
  participant Worklets
  participant UIRuntime
  EventHandler->>Worklets: create shareable update map
  Worklets->>UIRuntime: initialize map on UI runtime
  UIRuntime-->>EventHandler: return shareable map
Loading

Possibly related PRs

Suggested reviewers: m-bert

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the primary change: replacing makeMutable with createShareable.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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 updates the Reanimated integration in the v3 gesture-handler codepath to use react-native-worklets shareables (createShareable) instead of Reanimated’s makeMutable, and exposes Worklets alongside Reanimated from the shared wrapper.

Changes:

  • Switch the per-handler “last update event” map from Reanimated.makeMutable to Worklets.createShareable.
  • Extend the Reanimated wrapper to optionally load/export react-native-worklets and pass its UI runtime holder during runtime-bindings installation.

Reviewed changes

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

File Description
packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts Replaces makeMutable map creation with Worklets shareable map and updates related types/comments.
packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts Adds optional Worklets loading/export and adjusts UI runtime bindings installation setup.
Suppressed comments (1)

packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts:112

  • This comment is inaccurate with the current logic: updateEventMap becomes undefined when Worklets is absent, but Reanimated?.useEvent(...) can still register the callback if Reanimated is present. Either adjust the comment, or (preferably) restore the Reanimated fallback so updateEventMap is only undefined when neither runtime provider is available.
    // Undefined only when Worklets is absent — and then this callback is
    // never registered (`Reanimated?.useEvent` below short-circuits).
    if (updateEventMap === undefined) {

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts`:
- Around line 35-45: The Jest expectation for installUIRuntimeBindings is
failing because runtime binding initialization is invoked more than once. Update
the WorkletsPackage integration in reanimatedWrapper.ts (around lines 35-45) and
the related useReanimatedEventHandler.ts integration (around lines 7-10) so the
binding installation is performed only once, while preserving the existing
shareable-host and event-handler behavior; verify yarn test passes.

In
`@packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts`:
- Around line 31-40: Update the shareable-state fallback in the hook using
Reanimated’s makeMutable API when Worklets.createShareable or UIRuntimeId is
unavailable, so Reanimated.useEvent can still register and execute gesture
callbacks. Revise the comment near the Reanimated.useEvent registration to
reflect that missing Worklets APIs do not short-circuit registration.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 386e69e8-e8d3-4d28-8b66-673390aca58e

📥 Commits

Reviewing files that changed from the base of the PR and between 2b37b3c and 6de6580.

📒 Files selected for processing (2)
  • packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts
  • packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts

@tjzel tjzel changed the title @tjzel/drop in worklets refactor: replace makeMutable with createShareable Aug 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.ts`:
- Around line 5-9: Guard the Worklets dependency before invoking
installUIRuntimeBindings: pass Worklets?.getUIRuntimeHolder or initialize the
unsupported-setup contract as an empty object so the installer receives
undefined instead of dereferencing an unavailable module. Add a test covering
the missing react-native-worklets case and confirming graceful installation
without throwing.

In
`@packages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.ts`:
- Around line 9-14: Update the capability guard in the last-update event map
factory so missing Worklets.createShareable or Worklets.UIRuntimeId does not
immediately return undefined when Reanimated is available; preserve and use the
existing Reanimated-backed shared-map fallback for those cases, while retaining
the undefined result only when neither supported implementation is available.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 92f6f036-b303-4287-a016-f228bf9dae5a

📥 Commits

Reviewing files that changed from the base of the PR and between eb4f501 and 8ac28ff.

📒 Files selected for processing (6)
  • packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.ts
  • packages/react-native-gesture-handler/src/handlers/gestures/installUIRuntimeBindings.web.ts
  • packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts
  • packages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.ts
  • packages/react-native-gesture-handler/src/v3/hooks/callbacks/lastUpdateEventMap.web.ts
  • packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/react-native-gesture-handler/src/v3/hooks/callbacks/useReanimatedEventHandler.ts
  • packages/react-native-gesture-handler/src/handlers/gestures/reanimatedWrapper.ts

@tjzel
tjzel merged commit 8ba11c5 into main Aug 10, 2026
6 checks passed
@tjzel
tjzel deleted the @tjzel/drop-in-worklets branch August 10, 2026 08:33
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.

4 participants