diff --git a/React/CxxBridge/RCTCxxBridge.mm b/React/CxxBridge/RCTCxxBridge.mm index 5c5f3fe4e1..b458854ecd 100644 --- a/React/CxxBridge/RCTCxxBridge.mm +++ b/React/CxxBridge/RCTCxxBridge.mm @@ -1062,19 +1062,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTCxxBridge enqueueApplicationScript]", nil); [self _tryAndHandleError:^{ + NSString *sourceUrlStr = deriveSourceURL(url); if (isRAMBundle(script)) { [self->_performanceLogger markStartForTag:RCTPLRAMBundleLoad]; - auto ramBundle = std::make_unique(url.path.UTF8String); + auto ramBundle = std::make_unique(sourceUrlStr.UTF8String); std::unique_ptr scriptStr = ramBundle->getStartupCode(); [self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; [self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize]; if (self->_reactInstance) { self->_reactInstance->loadUnbundle(std::move(ramBundle), std::move(scriptStr), - [[url absoluteString] UTF8String], false); + sourceUrlStr.UTF8String, false); } } else if (self->_reactInstance) { self->_reactInstance->loadScriptFromString(std::make_unique(script), - [[url absoluteString] UTF8String], false); + sourceUrlStr.UTF8String, false); } else { throw std::logic_error("Attempt to call loadApplicationScript: on uninitialized bridge"); } @@ -1092,19 +1093,20 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR - (void)executeApplicationScriptSync:(NSData *)script url:(NSURL *)url { [self _tryAndHandleError:^{ + NSString *sourceUrlStr = deriveSourceURL(url); if (isRAMBundle(script)) { [self->_performanceLogger markStartForTag:RCTPLRAMBundleLoad]; - auto ramBundle = std::make_unique(url.path.UTF8String); + auto ramBundle = std::make_unique(sourceUrlStr.UTF8String); std::unique_ptr scriptStr = ramBundle->getStartupCode(); [self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad]; [self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize]; if (self->_reactInstance) { self->_reactInstance->loadUnbundle(std::move(ramBundle), std::move(scriptStr), - [[url absoluteString] UTF8String], true); + sourceUrlStr.UTF8String, true); } } else if (self->_reactInstance) { self->_reactInstance->loadScriptFromString(std::make_unique(script), - [[url absoluteString] UTF8String], true); + sourceUrlStr.UTF8String, true); } else { throw std::logic_error("Attempt to call loadApplicationScriptSync: on uninitialized bridge"); } diff --git a/React/CxxModule/RCTCxxUtils.h b/React/CxxModule/RCTCxxUtils.h index 41e701dfb7..c07b6ff8a2 100644 --- a/React/CxxModule/RCTCxxUtils.h +++ b/React/CxxModule/RCTCxxUtils.h @@ -48,5 +48,6 @@ struct ValueEncoder { }; NSError *tryAndReturnError(const std::function& func); +NSString *deriveSourceURL(NSURL *url); } } diff --git a/React/CxxModule/RCTCxxUtils.mm b/React/CxxModule/RCTCxxUtils.mm index 73951be812..ec9f88afc8 100644 --- a/React/CxxModule/RCTCxxUtils.mm +++ b/React/CxxModule/RCTCxxUtils.mm @@ -133,4 +133,16 @@ NSError *tryAndReturnError(const std::function& func) { } } +NSString *deriveSourceURL(NSURL *url) { + NSString *sourceUrl; + if (url.isFileURL) { + // Url will contain only path to resource (i.g. file:// will be removed) + sourceUrl = url.path; + } else { + // Url will include protocol (e.g. http://) + sourceUrl = url.absoluteString; + } + return sourceUrl ?: @""; +} + } }