Skip to content

Commit

Permalink
fix: sourceUrl passed to eval for local and remote chunks (#711)
Browse files Browse the repository at this point in the history
* fix: always use url from config when evaluating bundles on Android

* chore: add changeset

* fix: use uniqueId as sourceUrl when evaluating bundles

* fix: data types in ios ScriptManager

* chore: update RNTA to newest version

* chore: update podfile locks
  • Loading branch information
jbroma authored Sep 30, 2024
1 parent f64c60b commit 7af6d5b
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 95 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-monkeys-relate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/repack': patch
---

fix: always use URL from Script config as `sourceUrl` when evaluating bundles on Android
16 changes: 8 additions & 8 deletions apps/tester-app/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost (1.83.0)
- callstack-repack (4.3.1):
- callstack-repack (5.0.0-alpha.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1188,7 +1188,7 @@ PODS:
- React-logger (= 0.74.3)
- React-perflogger (= 0.74.3)
- React-utils (= 0.74.3)
- ReactNativeHost (0.4.10):
- ReactNativeHost (0.4.12):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1211,7 +1211,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- ReactTestApp-DevSupport (3.8.9):
- ReactTestApp-DevSupport (3.9.7):
- React-Core
- React-jsi
- ReactTestApp-Resources (1.0.0-dev)
Expand Down Expand Up @@ -1342,7 +1342,7 @@ DEPENDENCIES:
- React-runtimescheduler (from `../node_modules/react-native/ReactCommon/react/renderer/runtimescheduler`)
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "ReactNativeHost (from `../../../node_modules/.pnpm/react-native-test-app@3.8.9_react[email protected]_@[email protected]_@[email protected]_@_5gnl7gn4qdcfat774lcowqlmbu/node_modules/@rnx-kit/react-native-host`)"
- "ReactNativeHost (from `../../../node_modules/.pnpm/react-native-test-app@3.9.7_react[email protected]_@[email protected]_@[email protected]_@_yuccfljgtdkfvchsubtzqwjamu/node_modules/@rnx-kit/react-native-host`)"
- ReactTestApp-DevSupport (from `../node_modules/react-native-test-app`)
- ReactTestApp-Resources (from `..`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
Expand Down Expand Up @@ -1466,7 +1466,7 @@ EXTERNAL SOURCES:
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
ReactNativeHost:
:path: "../../../node_modules/.pnpm/react-native-test-app@3.8.9_react[email protected]_@[email protected]_@[email protected]_@_5gnl7gn4qdcfat774lcowqlmbu/node_modules/@rnx-kit/react-native-host"
:path: "../../../node_modules/.pnpm/react-native-test-app@3.9.7_react[email protected]_@[email protected]_@[email protected]_@_yuccfljgtdkfvchsubtzqwjamu/node_modules/@rnx-kit/react-native-host"
ReactTestApp-DevSupport:
:path: "../node_modules/react-native-test-app"
ReactTestApp-Resources:
Expand All @@ -1480,7 +1480,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
callstack-repack: ddc8a6429d0ebfda9806a76eb82fc3f4ffa50a28
callstack-repack: c4f8b184facdcebd023d32b662e7fd5a67db7b1f
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
FBLazyVector: 7e977dd099937dc5458851233141583abba49ff2
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
Expand Down Expand Up @@ -1534,8 +1534,8 @@ SPEC CHECKSUMS:
React-runtimescheduler: 0c80752bceb80924cb8a4babc2a8e3ed70d41e87
React-utils: a06061b3887c702235d2dac92dacbd93e1ea079e
ReactCommon: f00e436b3925a7ae44dfa294b43ef360fbd8ccc4
ReactNativeHost: fd9d65f6ee7947f468537d35b3fefe8b2bf546da
ReactTestApp-DevSupport: 874fb27318647f43f4243c5f3a47a246db9cec12
ReactNativeHost: ff797ad459a5acf88871c406100b1f50e50f917f
ReactTestApp-DevSupport: 74676edd899013becce4eaecc5eabba1fc51e26e
ReactTestApp-Resources: 0fa9146ee546fb7447198c96d852a56b8e3bb94a
RNCAsyncStorage: 7907926157e7c8d10ddfee0f6b3e9a105e060acf
RNSVG: 7b44aa4df2587946e28496adf2e10a16f08c1250
Expand Down
2 changes: 1 addition & 1 deletion apps/tester-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"get-port": "^6.1.2",
"globby": "^13.1.2",
"http-server": "^14.1.1",
"react-native-test-app": "^3.8.9",
"react-native-test-app": "^3.9.7",
"terser-webpack-plugin": "^5.3.10",
"typescript": "^5.5.3",
"vitest": "^2.0.5",
Expand Down
16 changes: 8 additions & 8 deletions apps/tester-federation/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- boost (1.83.0)
- callstack-repack (4.3.2):
- callstack-repack (5.0.0-alpha.0):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1254,7 +1254,7 @@ PODS:
- React-logger (= 0.74.3)
- React-perflogger (= 0.74.3)
- React-utils (= 0.74.3)
- ReactNativeHost (0.4.10):
- ReactNativeHost (0.4.12):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1277,7 +1277,7 @@ PODS:
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- ReactTestApp-DevSupport (3.8.9):
- ReactTestApp-DevSupport (3.9.7):
- React-Core
- React-jsi
- RNCAsyncStorage (1.24.0):
Expand Down Expand Up @@ -1410,7 +1410,7 @@ DEPENDENCIES:
- React-runtimescheduler (from `../node_modules/react-native/ReactCommon/react/renderer/runtimescheduler`)
- React-utils (from `../node_modules/react-native/ReactCommon/react/utils`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "ReactNativeHost (from `../../../node_modules/.pnpm/react-native-test-app@3.8.9_react[email protected]_@[email protected]_@[email protected]_@_5gnl7gn4qdcfat774lcowqlmbu/node_modules/@rnx-kit/react-native-host`)"
- "ReactNativeHost (from `../../../node_modules/.pnpm/react-native-test-app@3.9.7_react[email protected]_@[email protected]_@[email protected]_@_yuccfljgtdkfvchsubtzqwjamu/node_modules/@rnx-kit/react-native-host`)"
- ReactTestApp-DevSupport (from `../node_modules/react-native-test-app`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- RNScreens (from `../node_modules/react-native-screens`)
Expand Down Expand Up @@ -1535,7 +1535,7 @@ EXTERNAL SOURCES:
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
ReactNativeHost:
:path: "../../../node_modules/.pnpm/react-native-test-app@3.8.9_react[email protected]_@[email protected]_@[email protected]_@_5gnl7gn4qdcfat774lcowqlmbu/node_modules/@rnx-kit/react-native-host"
:path: "../../../node_modules/.pnpm/react-native-test-app@3.9.7_react[email protected]_@[email protected]_@[email protected]_@_yuccfljgtdkfvchsubtzqwjamu/node_modules/@rnx-kit/react-native-host"
ReactTestApp-DevSupport:
:path: "../node_modules/react-native-test-app"
RNCAsyncStorage:
Expand All @@ -1547,7 +1547,7 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
callstack-repack: b77e0c70a35bec3c965852b3a1b36ea52e6e8498
callstack-repack: c4f8b184facdcebd023d32b662e7fd5a67db7b1f
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
FBLazyVector: 7e977dd099937dc5458851233141583abba49ff2
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
Expand Down Expand Up @@ -1602,8 +1602,8 @@ SPEC CHECKSUMS:
React-runtimescheduler: 0c80752bceb80924cb8a4babc2a8e3ed70d41e87
React-utils: a06061b3887c702235d2dac92dacbd93e1ea079e
ReactCommon: f00e436b3925a7ae44dfa294b43ef360fbd8ccc4
ReactNativeHost: 4244bfacfd5f540290c4e79c3c1bf7e82d7e6c61
ReactTestApp-DevSupport: 874fb27318647f43f4243c5f3a47a246db9cec12
ReactNativeHost: 63c6ecbd3a7584111d8dc011975daf6fe04ef24e
ReactTestApp-DevSupport: 74676edd899013becce4eaecc5eabba1fc51e26e
RNCAsyncStorage: 7907926157e7c8d10ddfee0f6b3e9a105e060acf
RNScreens: d3d50aa84db4541eee00fbb1f32151030f56c510
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Expand Down
2 changes: 1 addition & 1 deletion apps/tester-federation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"get-port": "^6.1.2",
"globby": "^13.1.2",
"http-server": "^14.1.1",
"react-native-test-app": "^3.8.9",
"react-native-test-app": "^3.9.7",
"typescript": "^5.5.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class FileSystemScriptLoader(private val reactContext: ReactContext, private val
val path = config.url.path
val file = File(path)
val code: ByteArray = FileInputStream(file).use { it.readBytes() }
nativeLoader.evaluate(code, path, promise)
nativeLoader.evaluate(code, config.uniqueId, promise)
} else {
val assetName = config.url.file.split("/").last()
val inputStream = reactContext.assets.open(assetName)
val code: ByteArray = inputStream.use { it.readBytes() }
nativeLoader.evaluate(code, assetName, promise)
nativeLoader.evaluate(code, config.uniqueId, promise)
}
} catch (error: Exception) {
promise.reject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class RemoteScriptLoader(val reactContext: ReactContext, private val nativeLoade
throw Exception("Script file exists but could not be read: $file")
}

nativeLoader.evaluate(code, scriptPath, promise)
nativeLoader.evaluate(code, config.uniqueId, promise)
} catch (error: Exception) {
promise.reject(
ScriptLoadingError.ScriptEvalFailure.code,
Expand Down
8 changes: 4 additions & 4 deletions packages/repack/ios/ScriptManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ - (void)execute:(ScriptConfig *)config resolve:(RCTPromiseResolveBlock)resolve r
@throw [NSError errorWithDomain:errorMessage code:0 userInfo:nil];
}

[self evaluateJavascript:data url:config.url resolve:resolve reject:reject];
[self evaluateJavascript:data url:config.uniqueId resolve:resolve reject:reject];
} @catch (NSError *error) {
reject(CodeExecutionFailure, error.domain, nil);
}
Expand Down Expand Up @@ -304,7 +304,7 @@ - (void)executeFromFilesystem:(ScriptConfig *)config
filesystemScriptUrl = [[NSBundle mainBundle] URLForResource:scriptName withExtension:scriptExtension];
}
NSData *data = [[NSData alloc] initWithContentsOfFile:[filesystemScriptUrl path]];
[self evaluateJavascript:data url:filesystemScriptUrl resolve:resolve reject:reject];
[self evaluateJavascript:data url:config.uniqueId resolve:resolve reject:reject];
} @catch (NSError *error) {
reject(CodeExecutionFailure, error.localizedDescription, nil);
}
Expand All @@ -321,7 +321,7 @@ - (void)executeFromFilesystem:(ScriptConfig *)config
}

- (void)evaluateJavascript:(NSData *)code
url:(NSURL *)url
url:(NSString *)url
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject
{
Expand All @@ -341,7 +341,7 @@ - (void)evaluateJavascript:(NSData *)code
}

std::string source{static_cast<const char *>([code bytes]), [code length]};
std::string sourceUrl{[[url absoluteString] UTF8String]};
std::string sourceUrl{[url UTF8String]};

callInvoker->invokeAsync([source = std::move(source), sourceUrl = std::move(sourceUrl), runtime, resolve, reject]() {
// use c++ error handling here
Expand Down
Loading

0 comments on commit 7af6d5b

Please sign in to comment.