refactor(Worklets): two-step initialization#9203
Merged
Conversation
There was a problem hiding this comment.
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
WorkletsModuleProxyconstructor into a newWorkletsModuleProxy::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.
packages/react-native-worklets/android/src/networking/com/swmansion/worklets/WorkletsModule.kt
Outdated
Show resolved
Hide resolved
packages/react-native-worklets/src/WorkletsModule/NativeWorklets.native.ts
Outdated
Show resolved
Hide resolved
packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.cpp
Show resolved
Hide resolved
packages/react-native-worklets/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp
Show resolved
Hide resolved
packages/react-native-worklets/Common/cpp/worklets/NativeModules/WorkletsModuleProxy.cpp
Show resolved
Hide resolved
bartlomiejbloniarz
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Splitting initialization of
WorkletsModuleProxyinto two steps. Instead ofWorkletsModule.installTurboModule()starting all the native pipeline, it only creates an instance ofWorkletsModuleProxywhich is later on properly fully initialized withWorkletsModule.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