Skip to content

Commit b4785e5

Browse files
motiz88facebook-github-bot
authored andcommitted
Forward all bundle URL params through HMR and bundle splitting
Summary: Forwards any extra parameters set on the main bundle URL (in development) to the derived bundle URLs used in hot reloading and bundle splitting. Changelog: [General] - Forward URL parameters from main bundle to hot reloaded bundles Reviewed By: cpojer Differential Revision: D21455592 fbshipit-source-id: e1c375e3b6a0f3387372f1d96498dbf7d5237a09
1 parent 9b53591 commit b4785e5

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

Libraries/Core/Devtools/getDevServer.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import NativeSourceCode from '../../NativeModules/specs/NativeSourceCode';
1414

1515
let _cachedDevServerURL: ?string;
16+
let _cachedFullBundleURL: ?string;
1617
const FALLBACK = 'http://localhost:8081/';
1718

1819
type DevServerInfo = {
1920
url: string,
21+
fullBundleUrl: ?string,
2022
bundleLoadedFromServer: boolean,
2123
...
2224
};
@@ -27,14 +29,15 @@ type DevServerInfo = {
2729
*/
2830
function getDevServer(): DevServerInfo {
2931
if (_cachedDevServerURL === undefined) {
30-
const match = NativeSourceCode.getConstants().scriptURL.match(
31-
/^https?:\/\/.*?\//,
32-
);
32+
const scriptUrl = NativeSourceCode.getConstants().scriptURL;
33+
const match = scriptUrl.match(/^https?:\/\/.*?\//);
3334
_cachedDevServerURL = match ? match[0] : null;
35+
_cachedFullBundleURL = match ? scriptUrl : null;
3436
}
3537

3638
return {
3739
url: _cachedDevServerURL || FALLBACK,
40+
fullBundleUrl: _cachedFullBundleURL,
3841
bundleLoadedFromServer: _cachedDevServerURL !== null,
3942
};
4043
}

Libraries/Utilities/HMRClient.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const MetroHMRClient = require('metro/src/lib/bundle-modules/HMRClient');
1616
const Platform = require('./Platform');
1717
const prettyFormat = require('pretty-format');
1818

19+
import getDevServer from '../Core/Devtools/getDevServer';
1920
import NativeRedBox from '../NativeModules/specs/NativeRedBox';
2021
import * as LogBoxData from '../LogBox/Data/LogBoxData';
2122
import type {ExtendedError} from '../Core/Devtools/parseErrorStack';
@@ -159,8 +160,15 @@ const HMRClient: HMRClientNativeInterface = {
159160
const client = new MetroHMRClient(`ws://${wsHost}/hot`);
160161
hmrClient = client;
161162

163+
const {fullBundleUrl} = getDevServer();
162164
pendingEntryPoints.push(
163-
`ws://${wsHost}/hot?bundleEntry=${bundleEntry}&platform=${platform}`,
165+
// HMRServer understands regular bundle URLs, so prefer that in case
166+
// there are any important URL parameters we can't reconstruct from
167+
// `setup()`'s arguments.
168+
fullBundleUrl ??
169+
// The ws://.../hot?bundleEntry= format is an alternative to specifying
170+
// a regular HTTP bundle URL.
171+
`ws://${wsHost}/hot?bundleEntry=${bundleEntry}&platform=${platform}`,
164172
);
165173

166174
client.on('connection-error', e => {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
"pretty-format": "^26.0.1",
106106
"promise": "^8.0.3",
107107
"prop-types": "^15.7.2",
108+
"qs": "^6.5.1",
108109
"react-devtools-core": "^4.6.0",
109110
"react-refresh": "^0.4.0",
110111
"regenerator-runtime": "^0.13.2",

yarn.lock

+5
Original file line numberDiff line numberDiff line change
@@ -6231,6 +6231,11 @@ punycode@^2.1.0, punycode@^2.1.1:
62316231
resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec"
62326232
integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==
62336233

6234+
qs@^6.5.1:
6235+
version "6.9.4"
6236+
resolved "https://registry.yarnpkg.com/qs/-/qs-6.9.4.tgz#9090b290d1f91728d3c22e54843ca44aea5ab687"
6237+
integrity sha512-A1kFqHekCTM7cz0udomYUoYNWjBebHm/5wzU/XqrBRBNWectVH0QIiN+NEcZ0Dte5hvzHwbr8+XQmguPhJ6WdQ==
6238+
62346239
qs@~6.5.2:
62356240
version "6.5.2"
62366241
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"

0 commit comments

Comments
 (0)