[WebSocket] Fix race condition during initialization by gaearon · Pull Request #12305 · facebook/react-native · GitHub

Ever experienced flakiness of React Native Inspector in Nuclide? Just landed a fix for this.

  • facebook-github-bot added GH Review: accepted Import Started and removed GH Review: review-needed labels Feb 9, 2017
  • facebook-github-bot added GH Review: review-needed CLA Signed labels Feb 9, 2017
  • Gaearon referenced the pull request in facebook/react-devtools Feb 9, 2017
  • “` mkdir ~/my-server cd ~/my-server npm i ws nano index.js “` Paste this code: “`js const ws = require(‘ws’); const wss = new ws.
  • facebook-github-bot added a commit that closed this pull request Feb 9, 2017

react-native – A framework for building native apps with React.

@dan_abramov: Ever experienced flakiness of React Native Inspector in Nuclide? Just landed a fix for this.

We recommend upgrading to the latest Safari, Google Chrome, or Firefox.

I discovered this while trying to pinpoint why Nuclide Inspector integration with RN is so flaky. It turns out that, for some reason, if I create a

WebSocket

instance early enough (which I need to when setting up DevTools integration), and the connection is fast enough (which it is on localhost), the

websocketOpen

message may arrive earlier than an

onopen

event handler is registered, causing the

onopen

handler to never fire.

Paste this code:

Run the server:

Now, inside React Native, paste right after these lines:

The alert never shows up (or maybe shows up in some rare cases). The console output includes a debugging message indicating the problem:

The alert consistently shows up.

@mkonicek @javache

@javache has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

[WebSocket] Fix race condition during initialization by gaearon · Pull Request #12305 · facebook/react-native · GitHub