Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Conversation

gaearon
Copy link
Contributor

@gaearon gaearon commented Feb 7, 2017

Currently RN essentially uses a fork of backend/websocketConnect.js.

RN has a few special needs:

  • Customizing host and port.
  • Injecting RN style resolver.

In this PR, I am adding a new API to react-devtools-core that works like require('react-devtools') but provides additional customization for sophisticated consumers like RN. My work-in-progress rewrite of RN's setupDevtools now looks like this:

function setupDevtools() {
  var {connectToDevTools} = require('react-devtools-core');
  connectToDevTools({
    // Special case: Genymotion is running on a different host.
    host: (Platform.OS === 'android' && NativeModules.AndroidConstants) ?
      NativeModules.AndroidConstants.ServerHost.split(':')[0] :
      'localhost',
    // Read the optional global variable for backward compatibility.
    // It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
    port: window.__REACT_DEVTOOLS_PORT__,
    resolveRNStyle: require('flattenStyle'),
  });
}

It is still very flaky and often doesn’t connect, but the module boundaries themselves seem fine to me, and I’ll be cherry-picking some changes RN has made to the server so that it’s less flaky. (Might be some race condition or connection issue.)

So this is work in progress but I’d like feedback in case I’m going in a wrong direction.

@@ -10,13 +10,14 @@
*/
'use strict';

function websocketConnect(uri: string, WebSocket?: (val: string) => Object) {
WebSocket = WebSocket || window.WebSocket;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find where this is being used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - I think it was when I was experimenting with embedding in a webview or somewhere that didn't have a websocket impl.

@jaredly
Copy link
Contributor

jaredly commented Feb 7, 2017

Looks good!

@gaearon gaearon merged commit 432a3bf into facebook:master Feb 8, 2017
pastelsky pushed a commit to pastelsky/react-devtools that referenced this pull request Feb 25, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants