mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Support IPv6 dev server URLs in legacy standalone RDT connection
Summary: Changelog: [Internal] A minimal tweak to a legacy code path for React DevTools in React Native (**NOT** Fusebox!) that enables it to work / not crash when encountering an IPv6 dev server address. See doc comment for more. Reviewed By: hoxyq Differential Revision: D77150288 fbshipit-source-id: c11c742aad7b83861a1242dd13c5ed2753fbdf29
This commit is contained in:
committed by
Facebook GitHub Bot
parent
63d8d978f5
commit
49b7fff2a0
+21
-4
@@ -143,10 +143,7 @@ if (__DEV__) {
|
||||
// Get hostname from development server (packager)
|
||||
const devServer = getDevServer();
|
||||
const host = devServer.bundleLoadedFromServer
|
||||
? devServer.url
|
||||
.replace(/https?:\/\//, '')
|
||||
.replace(/\/$/, '')
|
||||
.split(':')[0]
|
||||
? guessHostFromDevServerUrl(devServer.url)
|
||||
: 'localhost';
|
||||
|
||||
// Read the optional global variable for backward compatibility.
|
||||
@@ -259,3 +256,23 @@ function readReloadAndProfileConfig(
|
||||
onReloadAndProfileFlagsReset,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a bad, no good, broken hack to get the host from a dev server URL for the purposes
|
||||
* of connecting to the legacy React DevTools socket (for the standalone react-devtools package).
|
||||
* It has too many bugs to list. Please don't use it in new code.
|
||||
*
|
||||
* The correct implementation would just be `return new URL(url).host`, but React Native does not
|
||||
* ship with a spec-compliant `URL` class yet. Alternatively, this can be deleted when we delete
|
||||
* `connectToWSBasedReactDevToolsFrontend`.
|
||||
*/
|
||||
function guessHostFromDevServerUrl(url: string): string {
|
||||
const hopefullyHostAndPort = url
|
||||
.replace(/https?:\/\//, '')
|
||||
.replace(/\/$/, '');
|
||||
// IPv6 addresses contain colons, so the split(':') below will return garbage.
|
||||
if (hopefullyHostAndPort.includes(']')) {
|
||||
return hopefullyHostAndPort.split(']')[0] + ']';
|
||||
}
|
||||
return hopefullyHostAndPort.split(':')[0];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user