react-native/Libraries
Dan Abramov 7a3ab96d94 Fix race condition during initialization
Summary:
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.

```
mkdir ~/my-server
cd ~/my-server
npm i ws
nano index.js
```

Paste this code:

```js
const ws = require('ws');
const wss = new ws.Server({
  port: 8099
});
```

Run the server:

```js
node index.js
```

Now, inside React Native, paste right after [these lines](57010d63b6/Libraries/Core/InitializeCore.js (L193-L194)):

```js
  const ws = new window.WebSocket('ws://localhost:8099');
  ws.onopen = function() {
    alert('open!');
  };
```

Closes https://github.com/facebook/react-native/pull/12305

Differential Revision: D4536554

Pulled By: gaearon

fbshipit-source-id: 3021fa26b3bf275cba3704a7f3a30c77db69a1f8
2017-02-09 13:32:31 -08:00
..
ART Better error for ART <Group /> 2016-12-07 17:13:42 -08:00
ActionSheetIOS Redo exported headers and include paths for opensource 2016-12-07 15:28:29 -08:00
AdSupport Redo exported headers and include paths for opensource 2016-12-07 15:28:29 -08:00
Alert Ensure documentation has consistent relative links 2017-01-31 12:13:31 -08:00
Animated findNodeHandle -> ReactNative.findNodeHandle 2017-02-08 19:17:08 -08:00
AppState docs(AppState.js): update example to ES6 2017-01-23 11:58:33 -08:00
BatchedBridge Some perf tools for debugging js stalls 2017-02-06 17:46:34 -08:00
BugReporting Patch up for future React Sync 2017-02-08 14:50:43 -08:00
CameraRoll Ensure documentation has consistent relative links 2017-01-31 12:13:31 -08:00
Components findNodeHandle -> ReactNative.findNodeHandle 2017-02-08 19:17:08 -08:00
Core Patch up for future React Sync 2017-02-08 14:50:43 -08:00
CustomComponents RN: Revert ListView Separator Change 2017-02-06 18:46:10 -08:00
DebugComponentHierarchy Move React Core Integration to a Dependency 2016-04-21 09:28:23 -07:00
EventEmitter RN: Cleanup OSS JS & Flow Declarations 2016-11-20 17:58:29 -08:00
Experimental removed flex: 1 from SwipeableRow styles to make compatible with 0.39 changes 2017-02-08 16:00:12 -08:00
Geolocation Update Geolocation.js 2017-01-31 11:58:30 -08:00
Image RN: Fix Type of `accessibilityLabel` in <Image> 2017-02-02 22:13:26 -08:00
Inspector Patch up for future React Sync 2017-02-08 14:50:43 -08:00
Interaction Some perf tools for debugging js stalls 2017-02-06 17:46:34 -08:00
JSInspector Add Network agent 2016-11-02 12:29:15 -07:00
LayoutAnimation Mention that LayoutAnimation has to be explicitly enabled on A… 2016-11-25 15:28:28 -08:00
Linking Auto-fix lint errors 2016-08-09 06:43:46 -07:00
LinkingIOS Redo exported headers and include paths for opensource 2016-12-07 15:28:29 -08:00
Modal Add property to force HW acceleration on Android for modal windows 2016-12-14 10:28:33 -08:00
NativeAnimation Drive any numerical prop via NativeAnimated 2017-01-26 18:28:53 -08:00
NavigationExperimental Deal with 0.38 'FlowFixMe's 2017-01-31 13:13:32 -08:00
Network Deal with 0.38 'FlowFixMe's 2017-01-31 13:13:32 -08:00
Performance Updated Systrace and RCTRenderingPerf to sync w/ React changes 2017-01-22 09:58:32 -08:00
PermissionsAndroid Update PermissionsAndroid docs to use new APIs 2017-01-09 00:43:31 -08:00
PushNotificationIOS Handle push notifications on iOS 2017-02-03 11:58:30 -08:00
RCTTest Apple TV support 4: support for input (tvOS focus engine) 2016-12-19 06:28:40 -08:00
ReactNative RN: Fix YellowBox Layout Bug 2017-02-08 19:17:08 -08:00
Renderer findNodeHandle -> ReactNative.findNodeHandle 2017-02-08 19:17:08 -08:00
Sample Fix missing RCTBridgeModule.h 2017-01-31 11:13:50 -08:00
Settings Redo exported headers and include paths for opensource 2016-12-07 15:28:29 -08:00
Share Update Share.js. Fixed bad grammar 2016-11-23 11:28:29 -08:00
Storage result in RCTAsyncStorage.multiGet could be null. 2016-12-15 22:43:30 -08:00
StyleSheet Patch up for future React Sync 2017-02-08 14:50:43 -08:00
Text Text docs - Update to improve readability for ellipsizeMode 2017-02-09 13:15:31 -08:00
Utilities Patch up for future React Sync 2017-02-08 14:50:43 -08:00
Vibration Redo exported headers and include paths for opensource 2016-12-07 15:28:29 -08:00
WebSocket Fix race condition during initialization 2017-02-09 13:32:31 -08:00
react-native Patch up for future React Sync 2017-02-08 14:50:43 -08:00
vendor RN: Cleanup OSS JS & Flow Declarations 2016-11-20 17:58:29 -08:00
Promise.js Make onUnhandled safe for undefined errors 2016-08-02 07:58:28 -07:00
promiseRejectionIsError.js RN: Cleanup OSS JS & Flow Declarations 2016-11-20 17:58:29 -08:00