Skip to content

refactor(Worklets): two-step initialization#9203

Merged
tjzel merged 3 commits intomainfrom
@tjzel/worklets/start
Mar 31, 2026
Merged

refactor(Worklets): two-step initialization#9203
tjzel merged 3 commits intomainfrom
@tjzel/worklets/start

Conversation

@tjzel
Copy link
Copy Markdown
Collaborator

@tjzel tjzel commented Mar 31, 2026

Summary

Splitting initialization of WorkletsModuleProxy into two steps. Instead of WorkletsModule.installTurboModule() starting all the native pipeline, it only creates an instance of WorkletsModuleProxy which is later on properly fully initialized with WorkletsModule.start().

This is necessary for

where WorkletsModuleProxy exposes bindings to register value unpackers code - thanks to that we don't have to pass the unpackers code from Kotlin/ObjC but have them exactly in C++ to use in Worklet Runtimes.

Test plan

Fabric Example runs both on iOS and Android

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors Worklets initialization into a two-step flow: installTurboModule() creates the WorkletsModuleProxy, and a new start() call completes native pipeline initialization (enabling C++-side runtime bindings/unpackers work per #8984).

Changes:

  • Added a start() method to the Worklets TurboModule spec and implemented it across JS/Native (iOS/Android/C++).
  • Moved UI-runtime initialization/runtime decoration work from WorkletsModuleProxy constructor into a new WorkletsModuleProxy::start().
  • Adjusted JSI utility API (optimizedFromHostObject) and wiring to decorate the RN runtime proxy earlier.

Reviewed changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/react-native-worklets/src/specs/NativeWorkletsModule.ts Adds start() to the TurboModule TypeScript spec.
packages/react-native-worklets/src/WorkletsModule/NativeWorklets.native.ts Calls start() after installTurboModule() and tightens RN-runtime detection.
packages/react-native-worklets/apple/worklets/apple/WorkletsModule.mm Exposes start as a blocking synchronous method on iOS.
packages/react-native-worklets/android/src/no-networking/com/swmansion/worklets/WorkletsModule.kt Adds synchronous start() and native startCpp() binding (no-networking flavor).
packages/react-native-worklets/android/src/networking/com/swmansion/worklets/WorkletsModule.kt Adds synchronous start() and native startCpp() binding (networking flavor).
packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.h Declares startCpp() in C++ hybrid module.
packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.cpp Implements startCpp() and registers it with JNI.
packages/react-native-worklets/android/CMakeLists.txt Minor target_link_libraries formatting/ordering tweak.
packages/react-native-worklets/Common/cpp/worklets/WorkletRuntime/WorkletRuntime.cpp Removes an include no longer needed after refactor.
packages/react-native-worklets/Common/cpp/worklets/Tools/WorkletsJSIUtils.h Changes optimizedFromHostObject signature to take const shared_ptr&.
packages/react-native-worklets/Common/cpp/worklets/Tools/WorkletsJSIUtils.cpp Updates optimizedFromHostObject definition accordingly.
packages/react-native-worklets/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.h Adds start() and stores RN runtime proxy instance.
packages/react-native-worklets/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp Moves UI runtime init/decorate logic into start(); decorates RN runtime in constructor.
apps/fabric-example/ios/Podfile.lock Updates dependency checksums from running pod install.

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

@tjzel tjzel added this pull request to the merge queue Mar 31, 2026
Merged via the queue into main with commit 651c563 Mar 31, 2026
25 checks passed
@tjzel tjzel deleted the @tjzel/worklets/start branch March 31, 2026 17:14
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