@onekeyfe/react-native-split-bundle-loader 1.1.51 → 1.1.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -135,15 +135,18 @@ class SplitBundleLoaderModule(reactContext: ReactApplicationContext) :
135
135
  // #19: Try CatalystInstance first (bridge mode), fall back to
136
136
  // ReactHost registerSegment if available (bridgeless / new arch).
137
137
  val reactContext = reactApplicationContext
138
+ val segStart = System.nanoTime()
138
139
  if (reactContext.hasCatalystInstance()) {
139
140
  reactContext.catalystInstance.registerSegment(segId, absolutePath)
140
- SBLLogger.info("Loaded segment $segmentKey (id=$segId)")
141
+ val segMs = (System.nanoTime() - segStart) / 1_000_000.0
142
+ SBLLogger.info("[SplitBundle] segment $segmentKey (id=$segId) registered in ${String.format("%.1f", segMs)}ms")
141
143
  promise.resolve(null)
142
144
  } else {
143
145
  // Bridgeless: try ReactHost via reflection
144
146
  val registered = tryRegisterViaBridgeless(segId, absolutePath)
147
+ val segMs = (System.nanoTime() - segStart) / 1_000_000.0
145
148
  if (registered) {
146
- SBLLogger.info("Loaded segment $segmentKey (id=$segId) via bridgeless")
149
+ SBLLogger.info("[SplitBundle] segment $segmentKey (id=$segId) registered via bridgeless in ${String.format("%.1f", segMs)}ms")
147
150
  promise.resolve(null)
148
151
  } else {
149
152
  promise.reject(
@@ -15,4 +15,14 @@
15
15
  resolve:(RCTPromiseResolveBlock)resolve
16
16
  reject:(RCTPromiseRejectBlock)reject;
17
17
 
18
+ /// Evaluate a JS bundle file inside the given RCTHost's runtime.
19
+ /// Used for the common + entry split-bundle loading strategy:
20
+ /// 1. RCTHost boots with common.jsbundle (polyfills + shared modules)
21
+ /// 2. After the runtime is ready, this evaluates the entry-specific bundle
22
+ /// (main.jsbundle or background.bundle) via jsi::Runtime::evaluateJavaScript.
23
+ ///
24
+ /// @param bundlePath Absolute filesystem path to the bundle file.
25
+ /// @param host The RCTHost whose runtime should evaluate the bundle.
26
+ + (void)loadEntryBundle:(NSString *)bundlePath inHost:(id)host;
27
+
18
28
  @end
@@ -1,6 +1,8 @@
1
1
  #import "SplitBundleLoader.h"
2
2
  #import "SBLLogger.h"
3
3
  #import <React/RCTBridge.h>
4
+ #import <objc/runtime.h>
5
+ #include <jsi/jsi.h>
4
6
 
5
7
  // Bridgeless (New Architecture) support: RCTHost segment registration
6
8
  @interface RCTHost (SplitBundle)
@@ -188,6 +190,52 @@
188
190
  }
189
191
  }
190
192
 
193
+ // MARK: - loadEntryBundle (common + entry split loading)
194
+
195
+ + (void)loadEntryBundle:(NSString *)bundlePath inHost:(id)host
196
+ {
197
+ if (!host || bundlePath.length == 0) {
198
+ [SBLLogger warn:[NSString stringWithFormat:@"loadEntryBundle: invalid arguments (host=%@, path=%@)", host, bundlePath]];
199
+ return;
200
+ }
201
+
202
+ Ivar ivar = class_getInstanceVariable([host class], "_instance");
203
+ if (!ivar) {
204
+ [SBLLogger warn:[NSString stringWithFormat:@"loadEntryBundle: _instance ivar not found on %@", [host class]]];
205
+ return;
206
+ }
207
+
208
+ id instance = object_getIvar(host, ivar);
209
+ if (!instance) {
210
+ [SBLLogger warn:@"loadEntryBundle: _instance is nil"];
211
+ return;
212
+ }
213
+
214
+ NSData *data = [NSData dataWithContentsOfFile:bundlePath];
215
+ if (!data || data.length == 0) {
216
+ [SBLLogger warn:[NSString stringWithFormat:@"loadEntryBundle: failed to read bundle at %@", bundlePath]];
217
+ return;
218
+ }
219
+
220
+ NSString *sourceURL = bundlePath.lastPathComponent ?: bundlePath;
221
+ CFAbsoluteTime startTime = CFAbsoluteTimeGetCurrent();
222
+ [SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] loadEntryBundle: evaluating %@ (%lu bytes)", sourceURL, (unsigned long)data.length]];
223
+
224
+ [instance callFunctionOnBufferedRuntimeExecutor:^(facebook::jsi::Runtime &runtime) {
225
+ @autoreleasepool {
226
+ CFAbsoluteTime evalStart = CFAbsoluteTimeGetCurrent();
227
+ auto buffer = std::make_shared<facebook::jsi::StringBuffer>(
228
+ std::string(static_cast<const char *>(data.bytes), data.length));
229
+ runtime.evaluateJavaScript(std::move(buffer), [sourceURL UTF8String]);
230
+ double evalMs = (CFAbsoluteTimeGetCurrent() - evalStart) * 1000.0;
231
+ [SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] loadEntryBundle: %@ evaluated in %.1fms", sourceURL, evalMs]];
232
+ }
233
+ }];
234
+
235
+ double totalMs = (CFAbsoluteTimeGetCurrent() - startTime) * 1000.0;
236
+ [SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] loadEntryBundle: %@ dispatched in %.1fms (eval is async)", sourceURL, totalMs]];
237
+ }
238
+
191
239
  // MARK: - loadSegment
192
240
 
193
241
  - (void)loadSegment:(double)segmentId
@@ -199,6 +247,7 @@
199
247
  {
200
248
  @try {
201
249
  int segId = (int)segmentId;
250
+ CFAbsoluteTime segStart = CFAbsoluteTimeGetCurrent();
202
251
 
203
252
  // Path traversal guard (#45)
204
253
  if ([relativePath containsString:@".."]) {
@@ -220,7 +269,8 @@
220
269
  // Register segment (#13: supports both bridge and bridgeless)
221
270
  NSError *regError = nil;
222
271
  if ([SplitBundleLoader registerSegment:segId path:absolutePath error:&regError]) {
223
- [SBLLogger info:[NSString stringWithFormat:@"Loaded segment %@ (id=%d)", segmentKey, segId]];
272
+ double segMs = (CFAbsoluteTimeGetCurrent() - segStart) * 1000.0;
273
+ [SBLLogger info:[NSString stringWithFormat:@"[SplitBundle] Loaded segment %@ (id=%d) in %.1fms", segmentKey, segId, segMs]];
224
274
  resolve(nil);
225
275
  } else {
226
276
  reject(@"SPLIT_BUNDLE_NO_RUNTIME",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-split-bundle-loader",
3
- "version": "1.1.51",
3
+ "version": "1.1.53",
4
4
  "description": "react-native-split-bundle-loader",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",