From 9b5359133b46b16be200e37dba0b03d82b73b4a0 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Tue, 12 May 2020 07:31:22 -0700 Subject: [PATCH] Add package name / bundle ID to bundle URL in development Summary: Adds the package name (Android) / bundle ID (iOS) as a new URL parameter named `app` in the bundle URL. This currently has no effect on Metro, which will ignore it for bundling / caching purposes. Changelog: [General] - Add package name / bundle ID to bundle URL in development Reviewed By: cpojer Differential Revision: D21429764 fbshipit-source-id: 394fe50dba72219f7594ebeac9486a8264a836a6 --- RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m | 4 ++-- React/Base/RCTBundleURLProvider.m | 4 ++++ .../java/com/facebook/react/devsupport/DevServerHelper.java | 5 +++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m b/RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m index 37ac407beba..c2f406d7252 100644 --- a/RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m +++ b/RNTester/RNTesterUnitTests/RCTBundleURLProviderTests.m @@ -20,12 +20,12 @@ static NSURL *mainBundleURL() static NSURL *localhostBundleURL() { - return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true&minify=false", testFile]]; + return [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8081/%@.bundle?platform=ios&dev=true&minify=false&app=com.apple.dt.xctest.tool", testFile]]; } static NSURL *ipBundleURL() { - return [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&minify=false", testFile]]; + return [NSURL URLWithString:[NSString stringWithFormat:@"http://192.168.1.1:8081/%@.bundle?platform=ios&dev=true&minify=false&app=com.apple.dt.xctest.tool", testFile]]; } @implementation NSBundle (RCTBundleURLProviderTests) diff --git a/React/Base/RCTBundleURLProvider.m b/React/Base/RCTBundleURLProvider.m index 3f30f1c5b05..c76b77244e5 100644 --- a/React/Base/RCTBundleURLProvider.m +++ b/React/Base/RCTBundleURLProvider.m @@ -187,6 +187,10 @@ static NSURL *serverRootWithHostPort(NSString *hostPort) NSString *query = [NSString stringWithFormat:@"platform=ios&dev=%@&minify=%@", enableDev ? @"true" : @"false", enableMinification ? @"true" : @"false"]; + NSString *bundleID = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleIdentifierKey]; + if (bundleID) { + query = [NSString stringWithFormat:@"%@&app=%@", query, bundleID]; + } return [[self class] resourceURLForResourcePath:path packagerHost:packagerHost query:query]; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java index 5c5bad9eb4a..b539282d635 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevServerHelper.java @@ -421,12 +421,13 @@ public class DevServerHelper { private String createBundleURL(String mainModuleID, BundleType type, String host) { return String.format( Locale.US, - "http://%s/%s.%s?platform=android&dev=%s&minify=%s", + "http://%s/%s.%s?platform=android&dev=%s&minify=%s&app=%s", host, mainModuleID, type.typeID(), getDevMode(), - getJSMinifyMode()); + getJSMinifyMode(), + mPackageName); } private String createBundleURL(String mainModuleID, BundleType type) {