diff --git a/.yarn/patches/react-native-npm-0.82.0-rc.0-4775a171a4.patch b/.yarn/patches/react-native-npm-0.82.0-rc.0-4775a171a4.patch deleted file mode 100644 index 352f213372d9..000000000000 --- a/.yarn/patches/react-native-npm-0.82.0-rc.0-4775a171a4.patch +++ /dev/null @@ -1,551 +0,0 @@ -diff --git a/React/Base/RCTBundleConsumer.h b/React/Base/RCTBundleConsumer.h -new file mode 100644 -index 0000000000000000000000000000000000000000..8f1eb972424b038daba818a9bbbe51431aa447dd ---- /dev/null -+++ b/React/Base/RCTBundleConsumer.h -@@ -0,0 +1,20 @@ -+/* -+ * Copyright (c) Meta Platforms, Inc. and affiliates. -+ * -+ * This source code is licensed under the MIT license found in the -+ * LICENSE file in the root directory of this source tree. -+ */ -+ -+#import -+#import -+ -+/** -+ * Provides the interface needed to register a Bundle Consumer module. -+ */ -+@protocol RCTBundleConsumer -+ -+@property (nonatomic, strong, readwrite) NSBigStringBuffer *scriptBuffer; -+ -+@property (nonatomic, strong, readwrite) NSString *sourceURL; -+ -+@end -diff --git a/React/CxxBridge/NSBigStringBuffer.h b/React/CxxBridge/NSBigStringBuffer.h -new file mode 100644 -index 0000000000000000000000000000000000000000..8643c17a5ae5119cdacd6630e77b162dccf8c482 ---- /dev/null -+++ b/React/CxxBridge/NSBigStringBuffer.h -@@ -0,0 +1,29 @@ -+/* -+ * Copyright (c) Meta Platforms, Inc. and affiliates. -+ * -+ * This source code is licensed under the MIT license found in the -+ * LICENSE file in the root directory of this source tree. -+ */ -+ -+#import -+ -+#ifdef __cplusplus -+#import -+#import -+ -+using namespace facebook; -+using namespace facebook::react; -+#endif // __cplusplus -+ -+@interface NSBigStringBuffer : NSObject -+#ifdef __cplusplus -+ -+{ -+ std::shared_ptr _buffer; -+} -+ -+- (instancetype)initWithSharedPtr:(const std::shared_ptr &)buffer; -+- (const std::shared_ptr &)getBuffer; -+#endif // __cplusplus -+ -+@end -diff --git a/React/CxxBridge/NSBigStringBuffer.mm b/React/CxxBridge/NSBigStringBuffer.mm -new file mode 100644 -index 0000000000000000000000000000000000000000..20ec1a93bc7f418c0690db8c5519174086e962c2 ---- /dev/null -+++ b/React/CxxBridge/NSBigStringBuffer.mm -@@ -0,0 +1,23 @@ -+/* -+ * Copyright (c) Meta Platforms, Inc. and affiliates. -+ * -+ * This source code is licensed under the MIT license found in the -+ * LICENSE file in the root directory of this source tree. -+ */ -+ -+#import "NSBigStringBuffer.h" -+ -+@implementation NSBigStringBuffer -+ -+- (instancetype)initWithSharedPtr:(const std::shared_ptr&)buffer { -+ if (self = [super init]) { -+ _buffer = buffer; -+ } -+ return self; -+} -+ -+- (const std::shared_ptr&)getBuffer { -+ return _buffer; -+} -+ -+@end -diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/BundleConsumer.kt b/ReactAndroid/src/main/java/com/facebook/react/bridge/BundleConsumer.kt -new file mode 100644 -index 0000000000000000000000000000000000000000..a9f4656e0d95466da8bc2b1cdc6b9bf8639a2ced ---- /dev/null -+++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/BundleConsumer.kt -@@ -0,0 +1,15 @@ -+/* -+ * Copyright (c) Meta Platforms, Inc. and affiliates. -+ * -+ * This source code is licensed under the MIT license found in the -+ * LICENSE file in the root directory of this source tree. -+ */ -+ -+package com.facebook.react.bridge -+ -+import com.facebook.react.fabric.BigStringBufferWrapper -+ -+public interface BundleConsumer { -+ public fun setScriptWrapper(scriptWrapper: BigStringBufferWrapper) -+ public fun setSourceURL(sourceURL: String) -+} -diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/BigStringBufferWrapper.kt b/ReactAndroid/src/main/java/com/facebook/react/fabric/BigStringBufferWrapper.kt -new file mode 100644 -index 0000000000000000000000000000000000000000..1d41653271aa26d92779691bbce9c97b81290a59 ---- /dev/null -+++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/BigStringBufferWrapper.kt -@@ -0,0 +1,36 @@ -+/* -+ * Copyright (c) Meta Platforms, Inc. and affiliates. -+ * -+ * This source code is licensed under the MIT license found in the -+ * LICENSE file in the root directory of this source tree. -+ */ -+ -+package com.facebook.react.fabric -+ -+import android.annotation.SuppressLint -+import android.content.res.AssetManager -+import com.facebook.jni.HybridData -+import com.facebook.proguard.annotations.DoNotStripAny -+ -+/** TODO: Description */ -+@SuppressLint("MissingNativeLoadLibrary") -+@DoNotStripAny -+public class BigStringBufferWrapper { -+ -+ private val mHybridData: HybridData -+ -+ public constructor(fileName: String) { -+ mHybridData = initHybridFromFile(fileName) -+ } -+ -+ public constructor(assetManager: AssetManager, assetURL: String) { -+ mHybridData = initHybridFromAssets(assetManager, assetURL) -+ } -+ -+ private external fun initHybridFromFile(fileName: String): HybridData -+ -+ private external fun initHybridFromAssets( -+ assetManager: AssetManager, -+ assetURL: String -+ ): HybridData -+} -diff --git a/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt b/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt -index 96bb76b3b2a0926f08a7c25cf72c87d26258958b..1be57c5937f13826e8931cb6fca5acc7a0483ccc 100644 ---- a/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt -+++ b/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt -@@ -43,6 +43,7 @@ import com.facebook.react.common.annotations.UnstableReactNativeAPI - import com.facebook.react.devsupport.InspectorFlags.getIsProfilingBuild - import com.facebook.react.devsupport.StackTraceHelper - import com.facebook.react.devsupport.interfaces.DevSupportManager -+import com.facebook.react.fabric.BigStringBufferWrapper - import com.facebook.react.fabric.ComponentFactory - import com.facebook.react.fabric.FabricUIManager - import com.facebook.react.fabric.FabricUIManagerBinding -@@ -300,6 +301,18 @@ internal class ReactInstance( - } - } - -+ fun beforeLoad(scriptWrapper: BigStringBufferWrapper, sourceURL: String){ -+ val workletsModule = turboModuleManager.getModule("WorkletsModule") -+ if (workletsModule != null) { -+ val setScriptWrapperMethod = workletsModule::class.java.methods.find { it.name == "setScriptWrapper" } -+ val setSourceURLMethod = workletsModule::class.java.methods.find { it.name == "setSourceURL" } -+ if (setScriptWrapperMethod != null && setSourceURLMethod != null) { -+ setScriptWrapperMethod.invoke(workletsModule, scriptWrapper) -+ setSourceURLMethod.invoke(workletsModule, sourceURL) -+ } -+ } -+ } -+ - fun loadJSBundle(bundleLoader: JSBundleLoader) { - Systrace.beginSection(Systrace.TRACE_TAG_REACT, "ReactInstance.loadJSBundle") - bundleLoader.loadScript( -@@ -310,11 +323,17 @@ internal class ReactInstance( - loadSynchronously: Boolean, - ) { - context.sourceURL = sourceURL -- loadJSBundleFromFile(fileName, sourceURL) -+ val script = BigStringBufferWrapper(fileName); -+ -+ beforeLoad(script, sourceURL); -+ loadJSBundle(script, sourceURL) - } - - override fun loadSplitBundleFromFile(fileName: String, sourceURL: String) { -- loadJSBundleFromFile(fileName, sourceURL) -+ val script = BigStringBufferWrapper(fileName) -+ -+ beforeLoad(script, sourceURL); -+ loadJSBundle(script, sourceURL) - } - - override fun loadScriptFromAssets( -@@ -323,7 +342,11 @@ internal class ReactInstance( - loadSynchronously: Boolean, - ) { - context.sourceURL = assetURL -- loadJSBundleFromAssets(assetManager, assetURL) -+ val sourceURL = assetURL.removePrefix("assets://") -+ val script = BigStringBufferWrapper(assetManager, sourceURL) -+ -+ beforeLoad(script, assetURL); -+ loadJSBundle(script, assetURL) - } - - override fun setSourceURLs(deviceURL: String, remoteURL: String) { -@@ -438,7 +461,7 @@ internal class ReactInstance( - reactHostInspectorTarget: ReactHostInspectorTarget?, - ): HybridData - -- private external fun loadJSBundleFromFile(fileName: String, sourceURL: String) -+ private external fun loadJSBundle(scriptWrapper: BigStringBufferWrapper, sourceURL: String) - - private external fun loadJSBundleFromAssets(assetManager: AssetManager, assetURL: String) - -diff --git a/ReactAndroid/src/main/jni/react/fabric/BigStringBufferWrapper.cpp b/ReactAndroid/src/main/jni/react/fabric/BigStringBufferWrapper.cpp -new file mode 100644 -index 0000000000000000000000000000000000000000..8a9c9b7ebff1c1880f6ab9e102658bcd07bba15c ---- /dev/null -+++ b/ReactAndroid/src/main/jni/react/fabric/BigStringBufferWrapper.cpp -@@ -0,0 +1,55 @@ -+/* -+ * Copyright (c) Meta Platforms, Inc. and affiliates. -+ * -+ * This source code is licensed under the MIT license found in the -+ * LICENSE file in the root directory of this source tree. -+ */ -+ -+#include "BigStringBufferWrapper.h" -+#include -+#include -+ -+using namespace facebook::jni; -+ -+namespace facebook::react { -+jni::local_ref -+BigStringBufferWrapper::initHybridFromFile( -+ jni::alias_ref jThis, -+ std::string fileName) { -+ std::unique_ptr script; -+ RecoverableError::runRethrowingAsRecoverable( -+ [&fileName, &script]() { script = JSBigFileString::fromPath(fileName); }); -+ auto buffer = std::make_shared(std::move(script)); -+ return makeCxxInstance(buffer); -+} -+ -+jni::local_ref -+BigStringBufferWrapper::initHybridFromAssets( -+ jni::alias_ref jThis, -+ jni::alias_ref assetManager, -+ const std::string& sourceURL) { -+ auto manager = extractAssetManager(assetManager); -+ auto script = loadScriptFromAssets(manager, sourceURL); -+ auto buffer = std::make_shared(std::move(script)); -+ return makeCxxInstance(buffer); -+} -+ -+BigStringBufferWrapper::BigStringBufferWrapper( -+ const std::shared_ptr& script) -+ : script_(script) {} -+ -+const std::shared_ptr BigStringBufferWrapper::getScript() -+ const { -+ return script_; -+} -+ -+void BigStringBufferWrapper::registerNatives() { -+ registerHybrid( -+ {makeNativeMethod( -+ "initHybridFromFile", BigStringBufferWrapper::initHybridFromFile), -+ makeNativeMethod( -+ "initHybridFromAssets", -+ BigStringBufferWrapper::initHybridFromAssets)}); -+} -+ -+} // namespace facebook::react -diff --git a/ReactAndroid/src/main/jni/react/fabric/BigStringBufferWrapper.h b/ReactAndroid/src/main/jni/react/fabric/BigStringBufferWrapper.h -new file mode 100644 -index 0000000000000000000000000000000000000000..248f99faf1e0bf061b6fd24de5fd42ea4bd6394e ---- /dev/null -+++ b/ReactAndroid/src/main/jni/react/fabric/BigStringBufferWrapper.h -@@ -0,0 +1,47 @@ -+/* -+ * Copyright (c) Meta Platforms, Inc. and affiliates. -+ * -+ * This source code is licensed under the MIT license found in the -+ * LICENSE file in the root directory of this source tree. -+ */ -+ -+#pragma once -+ -+#include -+#include -+ -+#include -+#include -+#include -+ -+namespace facebook::react { -+ -+class BigStringBufferWrapper : public jni::HybridClass { -+ public: -+ constexpr static const char* const kJavaDescriptor = -+ "Lcom/facebook/react/fabric/BigStringBufferWrapper;"; -+ -+ static void registerNatives(); -+ -+ [[nodiscard]] const std::shared_ptr getScript() const; -+ -+ private: -+ static jni::local_ref initHybridFromFile( -+ jni::alias_ref jThis, -+ std::string fileName); -+ -+ static jni::local_ref -+ initHybridFromAssets( -+ jni::alias_ref jThis, -+ jni::alias_ref assetManager, -+ const std::string& assetURL); -+ -+ friend HybridBase; -+ -+ explicit BigStringBufferWrapper( -+ const std::shared_ptr& script); -+ -+ const std::shared_ptr script_; -+}; -+ -+} // namespace facebook::react -diff --git a/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp b/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp -index 2d411d4dc7af987fc60a5f60f42494a53e73ede1..3425c9e6067778ba85fe873cb0a8bf583f0e6113 100644 ---- a/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp -+++ b/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp -@@ -7,6 +7,7 @@ - - #include - -+#include "BigStringBufferWrapper.h" - #include "ComponentFactory.h" - #include "EventBeatManager.h" - #include "EventEmitterWrapper.h" -@@ -22,5 +23,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* /*unused*/) { - facebook::react::StateWrapperImpl::registerNatives(); - facebook::react::ComponentFactory::registerNatives(); - facebook::react::SurfaceHandlerBinding::registerNatives(); -+ facebook::react::BigStringBufferWrapper::registerNatives(); - }); - } -diff --git a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp -index 5ffd7492ba8132fce79ce1879b9f2a97f9810e62..5414a38d0210a74915814e34dcd0f7a8c2c8144b 100644 ---- a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp -+++ b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp -@@ -132,24 +132,11 @@ jni::local_ref JReactInstance::initHybrid( - jReactHostInspectorTarget); - } - --void JReactInstance::loadJSBundleFromAssets( -- jni::alias_ref assetManager, -- const std::string& assetURL) { -- const int kAssetsLength = 9; // strlen("assets://"); -- auto sourceURL = assetURL.substr(kAssetsLength); -- -- auto manager = extractAssetManager(assetManager); -- auto script = loadScriptFromAssets(manager, sourceURL); -- instance_->loadScript(std::move(script), sourceURL); --} -- --void JReactInstance::loadJSBundleFromFile( -- const std::string& fileName, -+void JReactInstance::loadJSBundle( -+ jni::alias_ref scriptWrapper, - const std::string& sourceURL) { -- std::unique_ptr script; -- RecoverableError::runRethrowingAsRecoverable( -- [&fileName, &script]() { script = JSBigFileString::fromPath(fileName); }); -- instance_->loadScript(std::move(script), sourceURL); -+ auto script = scriptWrapper->cthis()->getScript(); -+ instance_->loadScript(script, sourceURL); - } - - /** -@@ -219,10 +206,7 @@ void JReactInstance::registerNatives() { - makeNativeMethod("initHybrid", JReactInstance::initHybrid), - makeNativeMethod( - "createJSTimerExecutor", JReactInstance::createJSTimerExecutor), -- makeNativeMethod( -- "loadJSBundleFromAssets", JReactInstance::loadJSBundleFromAssets), -- makeNativeMethod( -- "loadJSBundleFromFile", JReactInstance::loadJSBundleFromFile), -+ makeNativeMethod("loadJSBundle", JReactInstance::loadJSBundle), - makeNativeMethod( - "getJSCallInvokerHolder", JReactInstance::getJSCallInvokerHolder), - makeNativeMethod( -diff --git a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h -index d6552a8a97895f8effb8e0631a7c72e6717b9247..ff9445980f7c37562a99b7ce7c52bb71ff3877d3 100644 ---- a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h -+++ b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h -@@ -13,6 +13,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -58,12 +59,8 @@ class JReactInstance : public jni::HybridClass { - - static void registerNatives(); - -- void loadJSBundleFromAssets( -- jni::alias_ref assetManager, -- const std::string& assetURL); -- -- void loadJSBundleFromFile( -- const std::string& fileName, -+ void loadJSBundle( -+ jni::alias_ref scriptWrapper, - const std::string& sourceURL); - - void callFunctionOnModule( -diff --git a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h -index 9ef16f4cc5cbd567e431eacff7441aeb165f40ec..5c0622ad990fa0e34db9142741a0e6434f1b08d6 100644 ---- a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h -+++ b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h -@@ -150,6 +150,7 @@ class JSI_EXPORT TurboModule : public jsi::HostObject { - private: - friend class TurboModuleBinding; - std::unique_ptr jsRepresentation_; -+ jsi::Runtime* representationRuntime_; - }; - - /** -diff --git a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp -index 5ac4fbd2f7ec06ce2a212ebde0a7702eae6ee8dd..41db0a07c35637ed7194f9e3238be98eb01bb71a 100644 ---- a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp -+++ b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp -@@ -178,6 +178,7 @@ jsi::Value TurboModuleBinding::getModule( - jsi::Object jsRepresentation(runtime); - weakJsRepresentation = - std::make_unique(runtime, jsRepresentation); -+ module->representationRuntime_ = &runtime; - - // Lazily populate the jsRepresentation, on property access. - // -diff --git a/ReactCommon/react/runtime/ReactInstance.cpp b/ReactCommon/react/runtime/ReactInstance.cpp -index ea24e5c8682ed94d407e9d69f6069a025646f4a7..8ba492d52d404851fe48807bfa1967fdc0fada0b 100644 ---- a/ReactCommon/react/runtime/ReactInstance.cpp -+++ b/ReactCommon/react/runtime/ReactInstance.cpp -@@ -216,17 +216,16 @@ std::string simpleBasename(const std::string& path) { - * preferably via the runtimeExecutor_. - */ - void ReactInstance::loadScript( -- std::unique_ptr script, -+ const std::shared_ptr& script, - const std::string& sourceURL, - std::function&& beforeLoad, - std::function&& afterLoad) { -- auto buffer = std::make_shared(std::move(script)); - std::string scriptName = simpleBasename(sourceURL); - - runtimeScheduler_->scheduleWork([this, - scriptName, - sourceURL, -- buffer = std::move(buffer), -+ script, - weakBufferedRuntimeExecuter = - std::weak_ptr( - bufferedRuntimeExecutor_), -@@ -242,7 +241,7 @@ void ReactInstance::loadScript( - ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str()); - } - -- runtime.evaluateJavaScript(buffer, sourceURL); -+ runtime.evaluateJavaScript(script, sourceURL); - - /** - * TODO(T183610671): We need a safe/reliable way to enable the js -diff --git a/ReactCommon/react/runtime/ReactInstance.h b/ReactCommon/react/runtime/ReactInstance.h -index 3c92b268f38c745140419d3f99d51f68a5263ee3..d9e69dc6563c35bc30fbb54ea3738e0ca6e93155 100644 ---- a/ReactCommon/react/runtime/ReactInstance.h -+++ b/ReactCommon/react/runtime/ReactInstance.h -@@ -48,7 +48,7 @@ class ReactInstance final : private jsinspector_modern::InstanceTargetDelegate { - BindingsInstallFunc bindingsInstallFunc) noexcept; - - void loadScript( -- std::unique_ptr script, -+ const std::shared_ptr& script, - const std::string& sourceURL, - std::function&& beforeLoad = nullptr, - std::function&& afterLoad = nullptr); -diff --git a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm -index f5e53529e42045543f2b37a6f19392f75297620c..f37e8ba3091790842c85f7be48dc17133a712261 100644 ---- a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm -+++ b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm -@@ -11,6 +11,7 @@ - - #import - #import -+#import - #import - #import - #import -@@ -19,6 +20,7 @@ - #import - #import - #import -+#import - #import - #import - #import -@@ -572,9 +574,19 @@ - (void)_loadScriptFromSource:(RCTSource *)source - } - - auto script = std::make_unique(source.data); -+ const auto scriptBuffer = std::make_shared(std::move(script)); - const auto *url = deriveSourceURL(source.url).UTF8String; - -- auto beforeLoad = [waitUntilModuleSetupComplete = self->_waitUntilModuleSetupComplete](jsi::Runtime &_) { -+ auto beforeLoad = [waitUntilModuleSetupComplete = self->_waitUntilModuleSetupComplete, turboModuleManager = self->_turboModuleManager, scriptBuffer, url](jsi::Runtime &_) { -+ @try { -+ id workletsModule = [turboModuleManager moduleForName:@"WorkletsModule".UTF8String]; -+ if ([workletsModule respondsToSelector:@selector(setScriptBuffer:)] && [workletsModule respondsToSelector:@selector(setSourceURL:)]) { -+ [workletsModule setScriptBuffer:[[NSBigStringBuffer alloc] initWithSharedPtr:scriptBuffer]]; -+ [workletsModule setSourceURL:@(url)]; -+ } -+ } @catch (NSException *exception) { -+ } -+ - if (waitUntilModuleSetupComplete) { - waitUntilModuleSetupComplete(); - } -@@ -582,7 +594,7 @@ - (void)_loadScriptFromSource:(RCTSource *)source - auto afterLoad = [](jsi::Runtime &_) { - [[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil]; - }; -- _reactInstance->loadScript(std::move(script), url, beforeLoad, afterLoad); -+ _reactInstance->loadScript(scriptBuffer, url, beforeLoad, afterLoad); - } - - - (void)_handleJSError:(const JsErrorHandler::ProcessedError &)error withRuntime:(jsi::Runtime &)runtime diff --git a/.yarn/patches/react-native-npm-0.82.0-rc.4-228ad0ffa7.patch b/.yarn/patches/react-native-npm-0.82.0-rc.4-228ad0ffa7.patch new file mode 100644 index 000000000000..5786993e420f --- /dev/null +++ b/.yarn/patches/react-native-npm-0.82.0-rc.4-228ad0ffa7.patch @@ -0,0 +1,962 @@ +diff --git a/React/Base/RCTBridgeModule.h b/React/Base/RCTBridgeModule.h +index 1fb3e3e0e7e..ec6ecf70d70 100644 +--- a/React/Base/RCTBridgeModule.h ++++ b/React/Base/RCTBridgeModule.h +@@ -22,6 +22,7 @@ + @class RCTModuleRegistry; + @class RCTViewRegistry; + @class RCTCallableJSModules; ++@class RCTBundleProvider; + + /** + * The type of a block that is capable of sending a response to a bridged +@@ -130,6 +131,16 @@ RCT_EXTERN_C_END + */ + @property (nonatomic, weak, readwrite) RCTBundleManager *bundleManager; + ++/** ++ * A reference to the RCTBundleProvider. Useful for modules that need to use ++ the app's JavaScript bundle and sourceURL. ++ * ++ * To implement this in your module, just add `@synthesize bundleProvider = ++ * _bundleProvider;`. If using Swift, add `@objc var bundleProvider: ++ * RCTBundleProvider!` to your module. ++ */ ++@property (nonatomic, weak, readwrite) RCTBundleProvider *bundleProvider; ++ + /** + * A reference to an RCTCallableJSModules. Useful for modules that need to + * call into methods on JavaScript modules registered as callable with +diff --git a/React/Base/RCTBridgeModuleDecorator.h b/React/Base/RCTBridgeModuleDecorator.h +index e7860967d1a..4724ba8e407 100644 +--- a/React/Base/RCTBridgeModuleDecorator.h ++++ b/React/Base/RCTBridgeModuleDecorator.h +@@ -23,11 +23,13 @@ + @property (nonatomic, strong, readonly) RCTViewRegistry *viewRegistry_DEPRECATED; + @property (nonatomic, strong, readonly) RCTModuleRegistry *moduleRegistry; + @property (nonatomic, strong, readonly) RCTBundleManager *bundleManager; ++@property (nonatomic, strong, readonly) RCTBundleProvider *bundleProvider; + @property (nonatomic, strong, readonly) RCTCallableJSModules *callableJSModules; + + - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + callableJSModules:(RCTCallableJSModules *)callableJSModules; + + - (void)attachInteropAPIsToModule:(id)bridgeModule; +diff --git a/React/Base/RCTBridgeModuleDecorator.m b/React/Base/RCTBridgeModuleDecorator.m +index 7f8e15417bc..397df7e4178 100644 +--- a/React/Base/RCTBridgeModuleDecorator.m ++++ b/React/Base/RCTBridgeModuleDecorator.m +@@ -12,12 +12,14 @@ @implementation RCTBridgeModuleDecorator + - (instancetype)initWithViewRegistry:(RCTViewRegistry *)viewRegistry + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + callableJSModules:(RCTCallableJSModules *)callableJSModules + { + if (self = [super init]) { + _viewRegistry_DEPRECATED = viewRegistry; + _moduleRegistry = moduleRegistry; + _bundleManager = bundleManager; ++ _bundleProvider = bundleProvider; + _callableJSModules = callableJSModules; + } + return self; +@@ -47,6 +49,17 @@ - (void)attachInteropAPIsToModule:(id)bridgeModule + bridgeModule.bundleManager = _bundleManager; + } + ++ /** ++ * Attach the RCTBundleProvider to this TurboModule, which allows this TurboModule to ++ * read from the app's bundle and sourceURL. ++ * ++ * Usage: In the TurboModule @implementation, include: ++ * `@synthesize bundleProvider = _bundleProvider` ++ */ ++ if([bridgeModule respondsToSelector:@selector(setBundleProvider:)]) { ++ bridgeModule.bundleProvider = _bundleProvider; ++ } ++ + /** + * Attach the RCTCallableJSModules to this TurboModule, which allows this TurboModule + * to call JS Module methods. +diff --git a/React/Base/RCTBundleProvider.h b/React/Base/RCTBundleProvider.h +new file mode 100644 +index 00000000000..451f7c4adfc +--- /dev/null ++++ b/React/Base/RCTBundleProvider.h +@@ -0,0 +1,25 @@ ++/* ++ * Copyright (c) Meta Platforms, Inc. and affiliates. ++ * ++ * This source code is licensed under the MIT license found in the ++ * LICENSE file in the root directory of this source tree. ++ */ ++ ++#import ++#ifdef __cplusplus ++#import ++#endif // __cplusplus ++ ++@class NSBundleWrapper; ++ ++/** ++ * Provides the interface needed to register a Bundle Provider module. ++ */ ++@interface RCTBundleProvider : NSObject ++ ++# ifdef __cplusplus ++- (std::shared_ptr)getBundle; ++# endif // __cplusplus ++- (NSString *)getSourceURL; ++ ++@end +diff --git a/React/Base/RCTBundleProvider.mm b/React/Base/RCTBundleProvider.mm +new file mode 100644 +index 00000000000..6e59a2a9a30 +--- /dev/null ++++ b/React/Base/RCTBundleProvider.mm +@@ -0,0 +1,32 @@ ++/* ++ * Copyright (c) Meta Platforms, Inc. and affiliates. ++ * ++ * This source code is licensed under the MIT license found in the ++ * LICENSE file in the root directory of this source tree. ++ */ ++ ++#import "RCTBundleProvider.h" ++ ++using namespace facebook::react; ++ ++@implementation RCTBundleProvider{ ++ std::shared_ptr _bundleBuffer; ++ NSString *_sourceURL; ++} ++ ++- (std::shared_ptr)getBundle { ++ return _bundleBuffer; ++} ++ ++- (void)setBundle:(std::shared_ptr)bundle { ++ _bundleBuffer = bundle; ++} ++ ++- (NSString *)getSourceURL { ++ return _sourceURL; ++} ++ ++- (void)setSourceURL:(NSString *)sourceURL { ++ _sourceURL = sourceURL; ++} ++@end +diff --git a/React/Base/RCTModuleData.h b/React/Base/RCTModuleData.h +index 812991e4d26..e2008a5eff3 100644 +--- a/React/Base/RCTModuleData.h ++++ b/React/Base/RCTModuleData.h +@@ -18,6 +18,7 @@ + @class RCTBundleManager; + @class RCTCallableJSModules; + @class RCTCallInvoker; ++@class RCTBundleProvider; + + typedef id (^RCTBridgeModuleProvider)(void); + +@@ -34,6 +35,7 @@ typedef id (^RCTBridgeModuleProvider)(void); + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + callableJSModules:(RCTCallableJSModules *)callableJSModules NS_DESIGNATED_INITIALIZER + __deprecated_msg("This API will be removed along with the legacy architecture."); + +@@ -42,6 +44,7 @@ typedef id (^RCTBridgeModuleProvider)(void); + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + callableJSModules:(RCTCallableJSModules *)callableJSModules NS_DESIGNATED_INITIALIZER + __deprecated_msg("This API will be removed along with the legacy architecture."); + +diff --git a/React/Base/RCTModuleData.mm b/React/Base/RCTModuleData.mm +index 225f6b3c16e..68dd317537b 100644 +--- a/React/Base/RCTModuleData.mm ++++ b/React/Base/RCTModuleData.mm +@@ -46,6 +46,7 @@ @implementation RCTModuleData { + RCTModuleRegistry *_moduleRegistry; + RCTViewRegistry *_viewRegistry_DEPRECATED; + RCTBundleManager *_bundleManager; ++ RCTBundleProvider *_bundleProvider; + RCTCallableJSModules *_callableJSModules; + BOOL _isInitialized; + } +@@ -100,6 +101,7 @@ - (instancetype)initWithModuleClass:(Class)moduleClass + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + callableJSModules:(RCTCallableJSModules *)callableJSModules + { + if (self = [super init]) { +@@ -121,6 +123,7 @@ - (instancetype)initWithModuleInstance:(id)instance + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + viewRegistry_DEPRECATED:(RCTViewRegistry *)viewRegistry_DEPRECATED + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + callableJSModules:(RCTCallableJSModules *)callableJSModules + { + if (self = [super init]) { +@@ -195,6 +198,7 @@ - (void)setUpInstanceAndBridge:(int32_t)requestId + [[RCTBridgeModuleDecorator alloc] initWithViewRegistry:_viewRegistry_DEPRECATED + moduleRegistry:_moduleRegistry + bundleManager:_bundleManager ++ bundleProvider:_bundleProvider + callableJSModules:_callableJSModules]; + [moduleDecorator attachInteropAPIsToModule:_instance]; + +diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm +index 9ea645d4752..25343e36ad2 100644 +--- a/React/CxxBridge/RCTCxxBridge.mm ++++ b/React/CxxBridge/RCTCxxBridge.mm +@@ -249,6 +249,7 @@ @implementation RCTCxxBridge { + RCTModuleRegistry *_objCModuleRegistry; + RCTViewRegistry *_viewRegistry_DEPRECATED; + RCTBundleManager *_bundleManager; ++ RCTBundleProvider *_bundleProvider; + RCTCallableJSModules *_callableJSModules; + std::atomic _loading; + std::atomic _valid; +@@ -293,6 +294,7 @@ - (RCTBridgeModuleDecorator *)bridgeModuleDecorator + return [[RCTBridgeModuleDecorator alloc] initWithViewRegistry:_viewRegistry_DEPRECATED + moduleRegistry:_objCModuleRegistry + bundleManager:_bundleManager ++ bundleProvider:_bundleProvider + callableJSModules:_callableJSModules]; + } + +@@ -815,6 +817,7 @@ - (void)updateModuleWithInstance:(id)instance + moduleRegistry:_objCModuleRegistry + viewRegistry_DEPRECATED:_viewRegistry_DEPRECATED + bundleManager:_bundleManager ++ bundleProvider:_bundleProvider + callableJSModules:_callableJSModules]; + moduleData.callInvokerProvider = self; + BridgeNativeModulePerfLogger::moduleDataCreateEnd([moduleName UTF8String], moduleDataId); +@@ -893,6 +896,7 @@ - (void)registerExtraModules + moduleRegistry:_objCModuleRegistry + viewRegistry_DEPRECATED:_viewRegistry_DEPRECATED + bundleManager:_bundleManager ++ bundleProvider:_bundleProvider + callableJSModules:_callableJSModules]; + BridgeNativeModulePerfLogger::moduleDataCreateEnd([moduleName UTF8String], moduleDataId); + +diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/BridgeReactContext.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/BridgeReactContext.java +index 1ccb8abad43..5e50bb62af1 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/bridge/BridgeReactContext.java ++++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/BridgeReactContext.java +@@ -25,6 +25,7 @@ import com.facebook.react.common.annotations.VisibleForTesting; + import com.facebook.react.common.annotations.internal.LegacyArchitecture; + import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel; + import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger; ++import com.facebook.react.fabric.BundleWrapper; + import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; + import java.util.Collection; + import java.util.Objects; +@@ -292,6 +293,16 @@ public class BridgeReactContext extends ReactApplicationContext { + return Objects.requireNonNull(mCatalystInstance).getFabricUIManager(); + } + ++ /** ++ * Get the JS bundle. ++ * ++ * @return The JS bundle set when the bundle was loaded ++ */ ++ @Override ++ public @Nullable BundleWrapper getBundle() { ++ return mCatalystInstance == null ? null : mCatalystInstance.getBundle(); ++ } ++ + /** + * Get the sourceURL for the JS bundle from the CatalystInstance. This method is needed for + * compatibility with bridgeless mode, which has no CatalystInstance. +diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.kt b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.kt +index 81ee574dd1d..024a18df9b9 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.kt ++++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.kt +@@ -12,6 +12,7 @@ package com.facebook.react.bridge + import com.facebook.proguard.annotations.DoNotStrip + import com.facebook.react.bridge.queue.ReactQueueConfiguration + import com.facebook.react.common.annotations.internal.LegacyArchitecture ++import com.facebook.react.fabric.BundleWrapper + import com.facebook.react.internal.turbomodule.core.interfaces.TurboModuleRegistry + import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder + import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHolder +@@ -39,6 +40,11 @@ public interface CatalystInstance : MemoryPressureListener, JSInstance, JSBundle + */ + public val sourceURL: String? + ++ /** ++ * Get the JS bundle that was run or `null` if no JS bundle has been run yet. ++ */ ++ public val bundle: BundleWrapper? ++ + // This is called from java code, so it won't be stripped anyway, but proguard will rename it, + // which this prevents. + @DoNotStrip public override fun invokeCallback(callbackID: Int, arguments: NativeArrayInterface) +diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java +index fd6af7089cc..8c08fc60a3c 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java ++++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstanceImpl.java +@@ -29,6 +29,7 @@ import com.facebook.react.common.annotations.VisibleForTesting; + import com.facebook.react.common.annotations.internal.LegacyArchitecture; + import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel; + import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger; ++import com.facebook.react.fabric.BundleWrapper; + import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags; + import com.facebook.react.internal.turbomodule.core.interfaces.TurboModuleRegistry; + import com.facebook.react.module.annotations.ReactModule; +@@ -107,6 +108,7 @@ public class CatalystInstanceImpl implements CatalystInstance { + + private boolean mJSBundleHasLoaded; + private @Nullable String mSourceURL; ++ private @Nullable BundleWrapper mBundle; + + private JavaScriptContextHolder mJavaScriptContextHolder; + private @Nullable TurboModuleRegistry mTurboModuleRegistry; +@@ -300,6 +302,11 @@ public class CatalystInstanceImpl implements CatalystInstance { + } + } + ++ @Override ++ public @Nullable BundleWrapper getBundle() { ++ return mBundle; ++ } ++ + @Override + public @Nullable String getSourceURL() { + return mSourceURL; +diff --git a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java +index 7a0655081a8..c49dffd0dca 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java ++++ b/ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java +@@ -26,6 +26,7 @@ import com.facebook.react.bridge.queue.MessageQueueThread; + import com.facebook.react.bridge.queue.ReactQueueConfiguration; + import com.facebook.react.common.LifecycleState; + import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; ++import com.facebook.react.fabric.BundleWrapper; + import java.lang.ref.WeakReference; + import java.util.Collection; + import java.util.concurrent.CopyOnWriteArraySet; +@@ -505,6 +506,13 @@ public abstract class ReactContext extends ContextWrapper { + */ + public abstract @Nullable UIManager getFabricUIManager(); + ++ /** ++ * Get the BundleWrapper for the JS bundle. ++ * ++ * @return The BundleWrapper containing the JS bundle. ++ */ ++ public abstract @Nullable BundleWrapper getBundle(); ++ + /** + * Get the sourceURL for the JS bundle from the CatalystInstance. This method is needed for + * compatibility with bridgeless mode, which has no CatalystInstance. +diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/BundleWrapper.kt b/ReactAndroid/src/main/java/com/facebook/react/fabric/BundleWrapper.kt +new file mode 100644 +index 00000000000..1a686f66bc1 +--- /dev/null ++++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/BundleWrapper.kt +@@ -0,0 +1,38 @@ ++/* ++ * Copyright (c) Meta Platforms, Inc. and affiliates. ++ * ++ * This source code is licensed under the MIT license found in the ++ * LICENSE file in the root directory of this source tree. ++ */ ++ ++package com.facebook.react.fabric ++ ++import android.annotation.SuppressLint ++import android.content.res.AssetManager ++import com.facebook.jni.HybridData ++import com.facebook.proguard.annotations.DoNotStripAny ++ ++/** ++ * A wrapper around a JavaScript bundle that is backed by a native C++ object. ++ */ ++@SuppressLint("MissingNativeLoadLibrary") ++@DoNotStripAny ++public class BundleWrapper { ++ ++ private val mHybridData: HybridData ++ ++ public constructor(fileName: String) { ++ mHybridData = initHybridFromFile(fileName) ++ } ++ ++ public constructor(assetManager: AssetManager, assetURL: String) { ++ mHybridData = initHybridFromAssets(assetManager, assetURL) ++ } ++ ++ private external fun initHybridFromFile(fileName: String): HybridData ++ ++ private external fun initHybridFromAssets( ++ assetManager: AssetManager, ++ assetURL: String ++ ): HybridData ++} +diff --git a/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessCatalystInstance.kt b/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessCatalystInstance.kt +index d70ec496050..8329317e6f5 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessCatalystInstance.kt ++++ b/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessCatalystInstance.kt +@@ -29,6 +29,7 @@ import com.facebook.react.common.annotations.VisibleForTesting + import com.facebook.react.common.annotations.internal.LegacyArchitecture + import com.facebook.react.common.annotations.internal.LegacyArchitectureLogLevel + import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger ++import com.facebook.react.fabric.BundleWrapper + import com.facebook.react.internal.turbomodule.core.interfaces.TurboModuleRegistry + import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder + import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHolder +@@ -137,6 +138,9 @@ internal class BridgelessCatalystInstance(private val reactHost: ReactHostImpl) + throw UnsupportedOperationException("Unimplemented method 'extendNativeModules'") + } + ++ override val bundle: BundleWrapper? ++ get() = throw UnsupportedOperationException("Unimplemented method 'getBundle'") ++ + override val sourceURL: String + get() = throw UnsupportedOperationException("Unimplemented method 'getSourceURL'") + +diff --git a/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt b/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt +index 6e6921ee950..a44ffa6817c 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt ++++ b/ReactAndroid/src/main/java/com/facebook/react/runtime/BridgelessReactContext.kt +@@ -25,6 +25,7 @@ import com.facebook.react.common.annotations.FrameworkAPI + import com.facebook.react.common.annotations.UnstableReactNativeAPI + import com.facebook.react.common.build.ReactBuildConfig + import com.facebook.react.devsupport.interfaces.DevSupportManager ++import com.facebook.react.fabric.BundleWrapper + import com.facebook.react.internal.featureflags.ReactNativeNewArchitectureFeatureFlags + import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler + import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder +@@ -43,6 +44,7 @@ import java.util.concurrent.atomic.AtomicReference + */ + internal class BridgelessReactContext(context: Context, private val reactHost: ReactHostImpl) : + ReactApplicationContext(context), EventDispatcherProvider { ++ private val bundleRef = AtomicReference() + private val sourceURLRef = AtomicReference() + private val TAG: String = this.javaClass.simpleName + +@@ -54,6 +56,12 @@ internal class BridgelessReactContext(context: Context, private val reactHost: R + + override fun getEventDispatcher(): EventDispatcher = reactHost.eventDispatcher + ++ override fun getBundle(): BundleWrapper? = bundleRef.get() ++ ++ fun setBundle(bundle: BundleWrapper?) { ++ bundleRef.set(bundle) ++ } ++ + override fun getSourceURL(): String? = sourceURLRef.get() + + fun setSourceURL(sourceURL: String?) { +diff --git a/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt b/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt +index 96bb76b3b2a..5228c58e535 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt ++++ b/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.kt +@@ -43,6 +43,7 @@ import com.facebook.react.common.annotations.UnstableReactNativeAPI + import com.facebook.react.devsupport.InspectorFlags.getIsProfilingBuild + import com.facebook.react.devsupport.StackTraceHelper + import com.facebook.react.devsupport.interfaces.DevSupportManager ++import com.facebook.react.fabric.BundleWrapper + import com.facebook.react.fabric.ComponentFactory + import com.facebook.react.fabric.FabricUIManager + import com.facebook.react.fabric.FabricUIManagerBinding +@@ -300,6 +301,11 @@ internal class ReactInstance( + } + } + ++ fun beforeLoad(bundle: BundleWrapper, sourceURL: String){ ++ context.setSourceURL(sourceURL) ++ context.setBundle(bundle) ++ } ++ + fun loadJSBundle(bundleLoader: JSBundleLoader) { + Systrace.beginSection(Systrace.TRACE_TAG_REACT, "ReactInstance.loadJSBundle") + bundleLoader.loadScript( +@@ -309,12 +315,17 @@ internal class ReactInstance( + sourceURL: String, + loadSynchronously: Boolean, + ) { +- context.sourceURL = sourceURL +- loadJSBundleFromFile(fileName, sourceURL) ++ val bundle = BundleWrapper(fileName); ++ ++ beforeLoad(bundle, sourceURL); ++ loadJSBundle(bundle, sourceURL) + } + + override fun loadSplitBundleFromFile(fileName: String, sourceURL: String) { +- loadJSBundleFromFile(fileName, sourceURL) ++ val bundle = BundleWrapper(fileName) ++ ++ beforeLoad(bundle, sourceURL) ++ loadJSBundle(bundle, sourceURL) + } + + override fun loadScriptFromAssets( +@@ -322,8 +333,11 @@ internal class ReactInstance( + assetURL: String, + loadSynchronously: Boolean, + ) { +- context.sourceURL = assetURL +- loadJSBundleFromAssets(assetManager, assetURL) ++ val sourceURL = assetURL.removePrefix("assets://") ++ val bundle = BundleWrapper(assetManager, sourceURL) ++ ++ beforeLoad(bundle, assetURL) ++ loadJSBundle(bundle, assetURL) + } + + override fun setSourceURLs(deviceURL: String, remoteURL: String) { +@@ -438,7 +452,7 @@ internal class ReactInstance( + reactHostInspectorTarget: ReactHostInspectorTarget?, + ): HybridData + +- private external fun loadJSBundleFromFile(fileName: String, sourceURL: String) ++ private external fun loadJSBundle(bundle: BundleWrapper, sourceURL: String) + + private external fun loadJSBundleFromAssets(assetManager: AssetManager, assetURL: String) + +diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ThemedReactContext.kt b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ThemedReactContext.kt +index d91b7f1b189..1257b348366 100644 +--- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/ThemedReactContext.kt ++++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/ThemedReactContext.kt +@@ -21,6 +21,7 @@ import com.facebook.react.bridge.ReactApplicationContext + import com.facebook.react.bridge.ReactContext + import com.facebook.react.bridge.UIManager + import com.facebook.react.common.annotations.internal.LegacyArchitecture ++import com.facebook.react.fabric.BundleWrapper + import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder + + /** +@@ -149,6 +150,8 @@ public class ThemedReactContext( + ) + override fun getFabricUIManager(): UIManager? = reactApplicationContext.getFabricUIManager() + ++ override fun getBundle(): BundleWrapper? = reactApplicationContext.getBundle() ++ + override fun getSourceURL(): String? = reactApplicationContext.getSourceURL() + + override fun registerSegment(segmentId: Int, path: String?, callback: Callback?) { +diff --git a/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.cpp b/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.cpp +new file mode 100644 +index 00000000000..ff3d82c60c1 +--- /dev/null ++++ b/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.cpp +@@ -0,0 +1,50 @@ ++/* ++ * Copyright (c) Meta Platforms, Inc. and affiliates. ++ * ++ * This source code is licensed under the MIT license found in the ++ * LICENSE file in the root directory of this source tree. ++ */ ++ ++#include "BundleWrapper.h" ++#include ++#include ++ ++using namespace facebook::jni; ++ ++namespace facebook::react { ++jni::local_ref BundleWrapper::initHybridFromFile( ++ jni::alias_ref jThis, ++ std::string fileName) { ++ std::unique_ptr script; ++ RecoverableError::runRethrowingAsRecoverable( ++ [&fileName, &script]() { script = JSBigFileString::fromPath(fileName); }); ++ auto bundle = std::make_shared(std::move(script)); ++ return makeCxxInstance(bundle); ++} ++ ++jni::local_ref BundleWrapper::initHybridFromAssets( ++ jni::alias_ref jThis, ++ jni::alias_ref assetManager, ++ const std::string& sourceURL) { ++ auto manager = extractAssetManager(assetManager); ++ auto script = loadScriptFromAssets(manager, sourceURL); ++ auto bundle = std::make_shared(std::move(script)); ++ return makeCxxInstance(bundle); ++} ++ ++BundleWrapper::BundleWrapper( ++ const std::shared_ptr& bundle) ++ : bundle_(bundle) {} ++ ++const std::shared_ptr BundleWrapper::getBundle() const { ++ return bundle_; ++} ++ ++void BundleWrapper::registerNatives() { ++ registerHybrid( ++ {makeNativeMethod( ++ "initHybridFromFile", BundleWrapper::initHybridFromFile), ++ makeNativeMethod( ++ "initHybridFromAssets", BundleWrapper::initHybridFromAssets)}); ++} ++} // namespace facebook::react +diff --git a/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.h b/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.h +new file mode 100644 +index 00000000000..eb044ecdd48 +--- /dev/null ++++ b/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.h +@@ -0,0 +1,45 @@ ++/* ++ * Copyright (c) Meta Platforms, Inc. and affiliates. ++ * ++ * This source code is licensed under the MIT license found in the ++ * LICENSE file in the root directory of this source tree. ++ */ ++ ++#pragma once ++ ++#include ++#include ++ ++#include ++#include ++#include ++ ++namespace facebook::react { ++ ++class BundleWrapper : public jni::HybridClass { ++ public: ++ constexpr static const char* const kJavaDescriptor = ++ "Lcom/facebook/react/fabric/BundleWrapper;"; ++ ++ static void registerNatives(); ++ ++ [[nodiscard]] const std::shared_ptr getBundle() const; ++ ++ private: ++ static jni::local_ref initHybridFromFile( ++ jni::alias_ref jThis, ++ std::string fileName); ++ ++ static jni::local_ref initHybridFromAssets( ++ jni::alias_ref jThis, ++ jni::alias_ref assetManager, ++ const std::string& assetURL); ++ ++ friend HybridBase; ++ ++ explicit BundleWrapper(const std::shared_ptr& bundle); ++ ++ const std::shared_ptr bundle_; ++}; ++ ++} // namespace facebook::react +diff --git a/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp b/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp +index 2d411d4dc7a..8fec1ae37be 100644 +--- a/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp ++++ b/ReactAndroid/src/main/jni/react/fabric/OnLoad.cpp +@@ -7,6 +7,7 @@ + + #include + ++#include "BundleWrapper.h" + #include "ComponentFactory.h" + #include "EventBeatManager.h" + #include "EventEmitterWrapper.h" +@@ -22,5 +23,6 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* /*unused*/) { + facebook::react::StateWrapperImpl::registerNatives(); + facebook::react::ComponentFactory::registerNatives(); + facebook::react::SurfaceHandlerBinding::registerNatives(); ++ facebook::react::BundleWrapper::registerNatives(); + }); + } +diff --git a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp +index 5ffd7492ba8..d40d77aa471 100644 +--- a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp ++++ b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp +@@ -132,24 +132,11 @@ jni::local_ref JReactInstance::initHybrid( + jReactHostInspectorTarget); + } + +-void JReactInstance::loadJSBundleFromAssets( +- jni::alias_ref assetManager, +- const std::string& assetURL) { +- const int kAssetsLength = 9; // strlen("assets://"); +- auto sourceURL = assetURL.substr(kAssetsLength); +- +- auto manager = extractAssetManager(assetManager); +- auto script = loadScriptFromAssets(manager, sourceURL); +- instance_->loadScript(std::move(script), sourceURL); +-} +- +-void JReactInstance::loadJSBundleFromFile( +- const std::string& fileName, ++void JReactInstance::loadJSBundle( ++ jni::alias_ref bundleWrapper, + const std::string& sourceURL) { +- std::unique_ptr script; +- RecoverableError::runRethrowingAsRecoverable( +- [&fileName, &script]() { script = JSBigFileString::fromPath(fileName); }); +- instance_->loadScript(std::move(script), sourceURL); ++ auto bundle = bundleWrapper->cthis()->getBundle(); ++ instance_->loadScript(bundle, sourceURL); + } + + /** +@@ -219,10 +206,7 @@ void JReactInstance::registerNatives() { + makeNativeMethod("initHybrid", JReactInstance::initHybrid), + makeNativeMethod( + "createJSTimerExecutor", JReactInstance::createJSTimerExecutor), +- makeNativeMethod( +- "loadJSBundleFromAssets", JReactInstance::loadJSBundleFromAssets), +- makeNativeMethod( +- "loadJSBundleFromFile", JReactInstance::loadJSBundleFromFile), ++ makeNativeMethod("loadJSBundle", JReactInstance::loadJSBundle), + makeNativeMethod( + "getJSCallInvokerHolder", JReactInstance::getJSCallInvokerHolder), + makeNativeMethod( +diff --git a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h +index d6552a8a978..ca4e72ac488 100644 +--- a/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h ++++ b/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.h +@@ -13,6 +13,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -58,12 +59,8 @@ class JReactInstance : public jni::HybridClass { + + static void registerNatives(); + +- void loadJSBundleFromAssets( +- jni::alias_ref assetManager, +- const std::string& assetURL); +- +- void loadJSBundleFromFile( +- const std::string& fileName, ++ void loadJSBundle( ++ jni::alias_ref bundleWrapper, + const std::string& sourceURL); + + void callFunctionOnModule( +diff --git a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h +index 9ef16f4cc5c..5c0622ad990 100644 +--- a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h ++++ b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.h +@@ -150,6 +150,7 @@ class JSI_EXPORT TurboModule : public jsi::HostObject { + private: + friend class TurboModuleBinding; + std::unique_ptr jsRepresentation_; ++ jsi::Runtime* representationRuntime_; + }; + + /** +diff --git a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp +index 5ac4fbd2f7e..41db0a07c35 100644 +--- a/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp ++++ b/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp +@@ -178,6 +178,7 @@ jsi::Value TurboModuleBinding::getModule( + jsi::Object jsRepresentation(runtime); + weakJsRepresentation = + std::make_unique(runtime, jsRepresentation); ++ module->representationRuntime_ = &runtime; + + // Lazily populate the jsRepresentation, on property access. + // +diff --git a/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm b/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +index 5168bbf415d..375550eb0fd 100644 +--- a/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm ++++ b/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModuleManager.mm +@@ -791,6 +791,7 @@ - (BOOL)_shouldCreateObjCModule:(Class)moduleClass + moduleRegistry:_bridge.moduleRegistry + viewRegistry_DEPRECATED:nil + bundleManager:nil ++ bundleProvider:nil + callableJSModules:nil]; + [_bridge registerModuleForFrameUpdates:(id)module withModuleData:data]; + } +diff --git a/ReactCommon/react/runtime/ReactInstance.cpp b/ReactCommon/react/runtime/ReactInstance.cpp +index ea24e5c8682..8ba492d52d4 100644 +--- a/ReactCommon/react/runtime/ReactInstance.cpp ++++ b/ReactCommon/react/runtime/ReactInstance.cpp +@@ -216,17 +216,16 @@ std::string simpleBasename(const std::string& path) { + * preferably via the runtimeExecutor_. + */ + void ReactInstance::loadScript( +- std::unique_ptr script, ++ const std::shared_ptr& script, + const std::string& sourceURL, + std::function&& beforeLoad, + std::function&& afterLoad) { +- auto buffer = std::make_shared(std::move(script)); + std::string scriptName = simpleBasename(sourceURL); + + runtimeScheduler_->scheduleWork([this, + scriptName, + sourceURL, +- buffer = std::move(buffer), ++ script, + weakBufferedRuntimeExecuter = + std::weak_ptr( + bufferedRuntimeExecutor_), +@@ -242,7 +241,7 @@ void ReactInstance::loadScript( + ReactMarker::RUN_JS_BUNDLE_START, scriptName.c_str()); + } + +- runtime.evaluateJavaScript(buffer, sourceURL); ++ runtime.evaluateJavaScript(script, sourceURL); + + /** + * TODO(T183610671): We need a safe/reliable way to enable the js +diff --git a/ReactCommon/react/runtime/ReactInstance.h b/ReactCommon/react/runtime/ReactInstance.h +index 3c92b268f38..d9e69dc6563 100644 +--- a/ReactCommon/react/runtime/ReactInstance.h ++++ b/ReactCommon/react/runtime/ReactInstance.h +@@ -48,7 +48,7 @@ class ReactInstance final : private jsinspector_modern::InstanceTargetDelegate { + BindingsInstallFunc bindingsInstallFunc) noexcept; + + void loadScript( +- std::unique_ptr script, ++ const std::shared_ptr& script, + const std::string& sourceURL, + std::function&& beforeLoad = nullptr, + std::function&& afterLoad = nullptr); +diff --git a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +index 12631915e88..fb893682056 100644 +--- a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm ++++ b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +@@ -10,6 +10,7 @@ + + #import + #import ++#import + #import + #import + #import +@@ -115,6 +116,7 @@ @implementation RCTHost { + NSURL *_oldDelegateBundleURL; + NSURL *_bundleURL; + RCTBundleManager *_bundleManager; ++ RCTBundleProvider *_bundleProvider; + RCTHostBundleURLProvider _bundleURLProvider; + RCTHostJSEngineProvider _jsEngineProvider; + +@@ -165,6 +167,7 @@ - (instancetype)initWithBundleURLProvider:(RCTHostBundleURLProvider)provider + _turboModuleManagerDelegate = turboModuleManagerDelegate; + _bundleManager = [RCTBundleManager new]; + _moduleRegistry = [RCTModuleRegistry new]; ++ _bundleProvider = [RCTBundleProvider new]; + _jsEngineProvider = [jsEngineProvider copy]; + _launchOptions = [launchOptions copy]; + +@@ -243,6 +246,7 @@ - (void)start + _instance = [[RCTInstance alloc] initWithDelegate:self + jsRuntimeFactory:[self _provideJSEngine] + bundleManager:_bundleManager ++ bundleProvider:_bundleProvider + turboModuleManagerDelegate:_turboModuleManagerDelegate + moduleRegistry:_moduleRegistry + parentInspectorTarget:_inspectorTarget.get() +@@ -446,6 +450,7 @@ - (void)_reloadWithShouldRestartSurfaces:(BOOL)shouldRestartSurfaces + _instance = [[RCTInstance alloc] initWithDelegate:self + jsRuntimeFactory:[self _provideJSEngine] + bundleManager:_bundleManager ++ bundleProvider:_bundleProvider + turboModuleManagerDelegate:_turboModuleManagerDelegate + moduleRegistry:_moduleRegistry + parentInspectorTarget:_inspectorTarget.get() +diff --git a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h +index 5d4ea87be9e..57bd143832e 100644 +--- a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h ++++ b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h +@@ -26,6 +26,7 @@ RCT_EXTERN NSString *RCTInstanceRuntimeDiagnosticFlags(void); + RCT_EXTERN void RCTInstanceSetRuntimeDiagnosticFlags(NSString *_Nullable flags); + + @class RCTBundleManager; ++@class RCTBundleProvider; + @class RCTInstance; + @class RCTJSThreadManager; + @class RCTModuleRegistry; +@@ -68,6 +69,7 @@ RCT_EXTERN void RCTInstanceSetRuntimeDiagnosticFlags(NSString *_Nullable flags); + - (instancetype)initWithDelegate:(id)delegate + jsRuntimeFactory:(std::shared_ptr)jsRuntimeFactory + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + turboModuleManagerDelegate:(id)turboModuleManagerDelegate + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget +diff --git a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +index f5e53529e42..353b78fb814 100644 +--- a/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm ++++ b/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +@@ -70,6 +70,11 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags) + sRuntimeDiagnosticFlags = [flags copy]; + } + ++@interface RCTBundleProvider : NSObject ++- (void)setBundle:(std::shared_ptr)bundleBuffer; ++- (void)setSourceURL:(NSString *)sourceURL; ++@end ++ + @interface RCTBridgelessDisplayLinkModuleHolder : NSObject + - (instancetype)initWithModule:(id)module; + @end +@@ -111,6 +116,7 @@ @implementation RCTInstance { + RCTPerformanceLogger *_performanceLogger; + RCTDisplayLink *_displayLink; + RCTTurboModuleManager *_turboModuleManager; ++ RCTBundleProvider *_bundleProvider; + std::mutex _invalidationMutex; + std::atomic _valid; + RCTJSThreadManager *_jsThreadManager; +@@ -128,6 +134,7 @@ @implementation RCTInstance { + - (instancetype)initWithDelegate:(id)delegate + jsRuntimeFactory:(std::shared_ptr)jsRuntimeFactory + bundleManager:(RCTBundleManager *)bundleManager ++ bundleProvider:(RCTBundleProvider *)bundleProvider + turboModuleManagerDelegate:(id)tmmDelegate + moduleRegistry:(RCTModuleRegistry *)moduleRegistry + parentInspectorTarget:(jsinspector_modern::HostTarget *)parentInspectorTarget +@@ -142,9 +149,11 @@ - (instancetype)initWithDelegate:(id)delegate + _jsRuntimeFactory = jsRuntimeFactory; + _appTMMDelegate = tmmDelegate; + _jsThreadManager = [RCTJSThreadManager new]; ++ _bundleProvider = bundleProvider; + _bridgeModuleDecorator = [[RCTBridgeModuleDecorator alloc] initWithViewRegistry:[RCTViewRegistry new] + moduleRegistry:moduleRegistry + bundleManager:bundleManager ++ bundleProvider:bundleProvider + callableJSModules:[RCTCallableJSModules new]]; + _parentInspectorTarget = parentInspectorTarget; + { +@@ -572,8 +581,12 @@ - (void)_loadScriptFromSource:(RCTSource *)source + } + + auto script = std::make_unique(source.data); ++ const auto scriptBuffer = std::make_shared(std::move(script)); + const auto *url = deriveSourceURL(source.url).UTF8String; + ++ [_bundleProvider setBundle:scriptBuffer]; ++ [_bundleProvider setSourceURL:@(url)]; ++ + auto beforeLoad = [waitUntilModuleSetupComplete = self->_waitUntilModuleSetupComplete](jsi::Runtime &_) { + if (waitUntilModuleSetupComplete) { + waitUntilModuleSetupComplete(); +@@ -582,7 +595,7 @@ - (void)_loadScriptFromSource:(RCTSource *)source + auto afterLoad = [](jsi::Runtime &_) { + [[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil]; + }; +- _reactInstance->loadScript(std::move(script), url, beforeLoad, afterLoad); ++ _reactInstance->loadScript(scriptBuffer, url, beforeLoad, afterLoad); + } + + - (void)_handleJSError:(const JsErrorHandler::ProcessedError &)error withRuntime:(jsi::Runtime &)runtime diff --git a/apps/fabric-example/ios/Podfile.lock b/apps/fabric-example/ios/Podfile.lock index 5e3fd3c31efc..9b1ff727a948 100644 --- a/apps/fabric-example/ios/Podfile.lock +++ b/apps/fabric-example/ios/Podfile.lock @@ -3190,10 +3190,10 @@ SPEC CHECKSUMS: RNReanimated: 3b47c33660454c6f9700b463e92daa282030866a RNScreens: 6ced6ae8a526512a6eef6e28c2286e1fc2d378c3 RNSVG: 287504b73fa0e90a605225aa9f852a86d5461e84 - RNWorklets: 991f94e4fa31fc20853e74d5d987426f8580cb0d + RNWorklets: 7119ae08263033c456c80d90794a312f2f88c956 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 Yoga: e80c5fabbc3e26311152fa20404cdfa14f16a11f -PODFILE CHECKSUM: db099f48c6dadedd8fc0a430129b75e561867ab9 +PODFILE CHECKSUM: 5d8c04f461eed0f22e86610877d94f2b8b838b8b COCOAPODS: 1.15.2 diff --git a/packages/react-native-worklets/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java b/packages/react-native-worklets/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java index bd0696b1de70..eba112f3940b 100644 --- a/packages/react-native-worklets/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java +++ b/packages/react-native-worklets/android/src/experimentalBundling/com/swmansion/worklets/WorkletsModule.java @@ -3,13 +3,12 @@ import androidx.annotation.OptIn; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.bridge.BundleConsumer; import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.queue.MessageQueueThread; import com.facebook.react.common.annotations.FrameworkAPI; -import com.facebook.react.fabric.BigStringBufferWrapper; +import com.facebook.react.fabric.BundleWrapper; import com.facebook.react.module.annotations.ReactModule; import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; import com.facebook.soloader.SoLoader; @@ -20,8 +19,7 @@ @SuppressWarnings("JavaJniMissingFunction") @ReactModule(name = WorkletsModule.NAME) -public class WorkletsModule extends NativeWorkletsModuleSpec - implements LifecycleEventListener, BundleConsumer { +public class WorkletsModule extends NativeWorkletsModuleSpec implements LifecycleEventListener { static { SoLoader.loadLibrary("worklets"); } @@ -39,19 +37,9 @@ protected HybridData getHybridData() { private final AndroidUIScheduler mAndroidUIScheduler; private final AnimationFrameQueue mAnimationFrameQueue; private boolean mSlowAnimationsEnabled; - private BigStringBufferWrapper mScriptWrapper = null; + private BundleWrapper mBundleWrapper = null; private String mSourceURL = null; - @Override - public void setScriptWrapper(BigStringBufferWrapper scriptWrapper) { - mScriptWrapper = scriptWrapper; - } - - @Override - public void setSourceURL(String sourceURL) { - mSourceURL = sourceURL; - } - /** * Invalidating concurrently could be fatal. It shouldn't happen in a normal flow, but it doesn't * cost us much to add synchronization for extra safety. @@ -64,7 +52,7 @@ private native HybridData initHybrid( MessageQueueThread messageQueueThread, CallInvokerHolderImpl jsCallInvokerHolder, AndroidUIScheduler androidUIScheduler, - BigStringBufferWrapper scriptWrapper, + BundleWrapper bundleWrapper, String sourceURL); public WorkletsModule(ReactApplicationContext reactContext) { @@ -90,13 +78,16 @@ public boolean installTurboModule() { var jsContext = Objects.requireNonNull(context.getJavaScriptContextHolder()).get(); var jsCallInvokerHolder = JSCallInvokerResolver.getJSCallInvokerHolder(context); + mSourceURL = context.getSourceURL(); + mBundleWrapper = context.getBundle(); + mHybridData = initHybrid( jsContext, mMessageQueueThread, jsCallInvokerHolder, mAndroidUIScheduler, - mScriptWrapper, + mBundleWrapper, mSourceURL); return true; } diff --git a/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.cpp b/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.cpp index 84979ee67e5c..9f8f67af2347 100644 --- a/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.cpp +++ b/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.cpp @@ -52,8 +52,7 @@ jni::local_ref WorkletsModule::initHybrid( jni::alias_ref androidUIScheduler #ifdef WORKLETS_BUNDLE_MODE , - jni::alias_ref - scriptWrapper, + jni::alias_ref bundleWrapper, const std::string &sourceURL #endif // WORKLETS_BUNDLE_MODE ) { @@ -63,7 +62,7 @@ jni::local_ref WorkletsModule::initHybrid( std::shared_ptr script = nullptr; #ifdef WORKLETS_BUNDLE_MODE - script = scriptWrapper->cthis()->getScript(); + script = bundleWrapper->cthis()->getBundle(); #else const auto sourceURL = std::string{}; #endif // WORKLETS_BUNDLE_MODE diff --git a/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.h b/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.h index d63c98f79523..3770363697f4 100644 --- a/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.h +++ b/packages/react-native-worklets/android/src/main/cpp/worklets/android/WorkletsModule.h @@ -6,7 +6,7 @@ #include #include #ifdef WORKLETS_BUNDLE_MODE -#include +#include #endif // WORKLETS_BUNDLE_MODE #include @@ -35,8 +35,7 @@ class WorkletsModule : public jni::HybridClass { androidUIScheduler #ifdef WORKLETS_BUNDLE_MODE , - jni::alias_ref - scriptWrapper, + jni::alias_ref bundleWrapper, const std::string &sourceURL #endif // WORKLETS_BUNDLE_MODE ); @@ -54,7 +53,7 @@ class WorkletsModule : public jni::HybridClass { jni::alias_ref messageQueueThread, const std::shared_ptr &jsCallInvoker, const std::shared_ptr &uiScheduler, - const std::shared_ptr &script, + const std::shared_ptr &bundle, const std::string &sourceURL); void invalidateCpp(); diff --git a/packages/react-native-worklets/apple/worklets/apple/WorkletsModule.mm b/packages/react-native-worklets/apple/worklets/apple/WorkletsModule.mm index 69b49a853884..d27547abf110 100644 --- a/packages/react-native-worklets/apple/worklets/apple/WorkletsModule.mm +++ b/packages/react-native-worklets/apple/worklets/apple/WorkletsModule.mm @@ -12,6 +12,11 @@ #import #import +#if __has_include() +// Bundle mode +#import +#endif // __has_include() + using worklets::RNRuntimeWorkletDecorator; using worklets::WorkletsModuleProxy; @@ -33,11 +38,10 @@ @implementation WorkletsModule { return workletsModuleProxy_; } -#if __has_include() +#if __has_include() // Bundle mode -@synthesize scriptBuffer = scriptBuffer_; -@synthesize sourceURL = sourceURL_; -#endif // __has_include() +@synthesize bundleProvider = bundleProvider_; +#endif // __has_include() - (void)checkBridgeless { @@ -66,8 +70,8 @@ - (void)checkBridgeless std::string sourceURL = ""; std::shared_ptr script = nullptr; #ifdef WORKLETS_BUNDLE_MODE - script = [scriptBuffer_ getBuffer]; - sourceURL = [sourceURL_ UTF8String]; + script = [bundleProvider_ getBundle]; + sourceURL = [[bundleProvider_ getSourceURL] UTF8String]; #endif // WORKLETS_BUNDLE_MODE auto jsCallInvoker = _callInvoker.callInvoker; diff --git a/scripts/patches/bundle-mode.patch b/scripts/patches/bundle-mode.patch index 4f538f424567..351f2acec26f 100644 --- a/scripts/patches/bundle-mode.patch +++ b/scripts/patches/bundle-mode.patch @@ -74,49 +74,18 @@ index cb4f1c4adc..b05b824d9c 100644 module.exports = wrapWithReanimatedMetroConfig( mergeConfig(getDefaultConfig(__dirname), config) -diff --git a/apps/fabric-example/package.json b/apps/fabric-example/package.json -index 7810a059bc..b8095d694e 100644 ---- a/apps/fabric-example/package.json -+++ b/apps/fabric-example/package.json -@@ -11,7 +11,7 @@ - }, - "dependencies": { - "common-app": "workspace:*", -- "react-native": "0.82.0-rc.0" -+ "react-native": "patch:react-native@npm%3A0.82.0-rc.0#~/.yarn/patches/react-native-npm-0.82.0-rc.0-4775a171a4.patch" - }, - "devDependencies": { - "prettier": "^3.3.3" diff --git a/package.json b/package.json -index 6a77357267..fa77b14543 100644 +index 6a77357267..df6817cce5 100644 --- a/package.json +++ b/package.json -@@ -49,5 +49,28 @@ +@@ -49,5 +49,10 @@ "prettier": "^3.3.3", "prettier-plugin-jsdoc": "^1.3.0", "typescript": "5.8.3" + }, + "resolutions": { -+ "@react-native/community-cli-plugin@npm:0.80.0": "patch:@react-native/community-cli-plugin@npm%3A0.80.0#~/.yarn/patches/@react-native-community-cli-plugin-npm-0.80.0-4137b3f35c.patch", -+ "metro@npm:^0.82.0": "patch:metro@npm%3A0.82.4#~/.yarn/patches/metro-npm-0.82.4-2c6a795208.patch", -+ "metro@npm:^0.82.2": "patch:metro@npm%3A0.82.4#~/.yarn/patches/metro-npm-0.82.4-2c6a795208.patch", -+ "metro@npm:0.82.4": "patch:metro@npm%3A0.82.4#~/.yarn/patches/metro-npm-0.82.4-2c6a795208.patch", -+ "metro@npm:0.80.12": "patch:metro@npm%3A0.82.4#~/.yarn/patches/metro-npm-0.82.4-2c6a795208.patch", -+ "metro@npm:0.82.1": "patch:metro@npm%3A0.82.4#~/.yarn/patches/metro-npm-0.82.4-2c6a795208.patch", -+ "metro@npm:0.82.3": "patch:metro@npm%3A0.82.4#~/.yarn/patches/metro-npm-0.82.4-2c6a795208.patch", -+ "metro@npm:^0.80.3": "patch:metro@npm%3A0.82.4#~/.yarn/patches/metro-npm-0.82.4-2c6a795208.patch", -+ "metro@npm:^0.83.1": "patch:metro@npm%3A0.83.1#~/.yarn/patches/metro-npm-0.83.1-241fe42591.patch", -+ "metro@npm:0.83.1": "patch:metro@npm%3A0.83.1#~/.yarn/patches/metro-npm-0.83.1-241fe42591.patch", -+ "metro@npm:0.82.5": "patch:metro@npm%3A0.83.1#~/.yarn/patches/metro-npm-0.83.1-241fe42591.patch", -+ "metro-runtime@npm:^0.80.3": "patch:metro-runtime@npm%3A0.82.4#~/.yarn/patches/metro-runtime-npm-0.82.4-32e8f779f8.patch", -+ "metro-runtime@npm:0.80.12": "patch:metro-runtime@npm%3A0.82.4#~/.yarn/patches/metro-runtime-npm-0.82.4-32e8f779f8.patch", -+ "metro-runtime@npm:0.82.1": "patch:metro-runtime@npm%3A0.82.4#~/.yarn/patches/metro-runtime-npm-0.82.4-32e8f779f8.patch", -+ "metro-runtime@npm:0.82.3": "patch:metro-runtime@npm%3A0.82.4#~/.yarn/patches/metro-runtime-npm-0.82.4-32e8f779f8.patch", -+ "metro-runtime@npm:^0.82.0": "patch:metro-runtime@npm%3A0.82.4#~/.yarn/patches/metro-runtime-npm-0.82.4-32e8f779f8.patch", -+ "metro-runtime@npm:^0.82.2": "patch:metro-runtime@npm%3A0.82.4#~/.yarn/patches/metro-runtime-npm-0.82.4-32e8f779f8.patch", -+ "metro-runtime@npm:0.82.4": "patch:metro-runtime@npm%3A0.82.4#~/.yarn/patches/metro-runtime-npm-0.82.4-32e8f779f8.patch", -+ "metro-runtime@npm:^0.83.1": "patch:metro-runtime@npm%3A0.83.1#~/.yarn/patches/metro-runtime-npm-0.83.1-c3d616063e.patch", -+ "metro-runtime@npm:0.83.1": "patch:metro-runtime@npm%3A0.83.1#~/.yarn/patches/metro-runtime-npm-0.83.1-c3d616063e.patch", -+ "metro-runtime@npm:0.82.5": "patch:metro-runtime@npm%3A0.83.1#~/.yarn/patches/metro-runtime-npm-0.83.1-c3d616063e.patch" ++ "metro": "patch:metro@npm%3A0.83.1#~/.yarn/patches/metro-npm-0.83.1-241fe42591.patch", ++ "metro-runtime": "patch:metro-runtime@npm%3A0.83.1#~/.yarn/patches/metro-runtime-npm-0.83.1-c3d616063e.patch", ++ "react-native": "patch:react-native@npm%3A0.82.0-rc.4#~/.yarn/patches/react-native-npm-0.82.0-rc.4-228ad0ffa7.patch" } }