Skip to content

Commit fa574c6

Browse files
jhen0409facebook-github-bot
authored andcommitted
Set host of development server for setupDevtools
Summary: Related to #15126, and this would be useful for use React DevTools on real device without modify `setupDevtools.js`. In Android emulator, the host of `SourceCode.scriptURL` is same with `PlatformConstants.ServerHost` so we can just replace it. * Tested on iOS device with [react-devtools](https://github.com/facebook/react-devtools/tree/master/packages/react-devtools) package. * Tested on Android emulator, the `getDevServer` module got the correctly hostname so that don't need `adb reverse`. [ENHANCEMENT] [setupDevtools] Set host of development server for setupDevtools Closes #15547 Differential Revision: D6544980 Pulled By: javache fbshipit-source-id: a286874bcef0501c5d2e0be2251d58c236a5534a
1 parent 52f350a commit fa574c6

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Libraries/Core/Devtools/setupDevtools.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ let register = function () {
2828
if (__DEV__) {
2929
const AppState = require('AppState');
3030
const WebSocket = require('WebSocket');
31-
const {PlatformConstants} = require('NativeModules');
3231
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an
3332
* error found when Flow v0.54 was deployed. To see the error delete this
3433
* comment and run Flow. */
3534
const reactDevTools = require('react-devtools-core');
35+
const getDevServer = require('getDevServer');
3636

3737
// Initialize dev tools only if the native module for WebSocket is available
3838
if (WebSocket.isAvailable) {
@@ -42,10 +42,11 @@ if (__DEV__) {
4242
// or the code will throw for bundles that don't have it.
4343
const isAppActive = () => AppState.currentState !== 'background';
4444

45-
// Special case: Genymotion is running on a different host.
46-
const host = PlatformConstants && PlatformConstants.ServerHost ?
47-
PlatformConstants.ServerHost.split(':')[0] :
48-
'localhost';
45+
// Get hostname from development server (packager)
46+
const devServer = getDevServer();
47+
const host = devServer.bundleLoadedFromServer
48+
? devServer.url.replace(/https?:\/\//, '').split(':')[0]
49+
: 'localhost';
4950

5051
reactDevTools.connectToDevTools({
5152
isAppActive,

0 commit comments

Comments
 (0)