react-native/Libraries
Eric Rozell 809f1e97de Avoid race condition for AppState.currentState
Summary:
When the AppState module is initialized, it subscribes to the `appStateDidChange` event and sends an async native method call to the AppState native module. There is a small race condition window where the native module can read the current app state as `uninitialized` before calling the JavaScript callback, and then be interrupted by the underlying mechanism to trigger the `appStateDidChange` event. If the `appStateDidChange` event is processed before the JavaScript callback, the resulting value of `AppState.currentState` will be invalid.

Fixes Microsoft/react-native-windows#1300

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Bonus points for screenshots and videos!)

I simulated (over-exaggerated) the race condition by injecting "thread sleep" calls in the native method call and the native mechanism for updating the app state.

I then ran the AppStateExample in the RNTester and found that the current app state was set to `uninitialized`, as opposed to the expected value of `active`.

Once I made this JavaScript change, the over-exaggerated race condition no longer resulted in an invalid app state.
Closes https://github.com/facebook/react-native/pull/15499

Differential Revision: D5660620

Pulled By: hramos

fbshipit-source-id: 47c0dca75d37f677191c48f2148a72edd9cdd0e2
2017-08-18 13:14:59 -07:00
..
ART Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
ActionSheetIOS Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
Alert Export Alert's type ButtonsArray for external use 2017-03-06 12:44:47 -08:00
Animated Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
AppState Avoid race condition for AppState.currentState 2017-08-18 13:14:59 -07:00
BatchedBridge Increase information logged to MessageQueue.spy 2017-07-31 06:16:41 -07:00
Blob Configure requiresMainQueueSetup for core modules 2017-08-07 07:04:36 -07:00
BugReporting Patch up for future React Sync 2017-02-08 14:50:43 -08:00
CameraRoll Fetching video length 2017-08-15 11:41:27 -07:00
Components Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Core Expose "register devtools plugin" interface globally in React-Native 2017-08-15 12:03:40 -07:00
EventEmitter Breaking - make RCTDeviceEventEmitter warnings fatal 2017-07-24 03:47:59 -07:00
Experimental Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Geolocation Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
Image Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Inspector Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Interaction Increase information logged to MessageQueue.spy 2017-07-31 06:16:41 -07:00
JSInspector Add Network agent 2016-11-02 12:29:15 -07:00
LayoutAnimation Fix prop-types warning in LayoutAnimation 2017-05-12 15:06:17 -07:00
Linking Docs: fix typo in deeplinking docs 2017-07-26 07:18:44 -07:00
LinkingIOS Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
Lists Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Modal Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
NativeAnimation Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
Network Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
Performance Gate more code with if (__DEV__) { } 2017-08-14 07:19:00 -07:00
PermissionsAndroid Update documentation for PermissionsAndroid 2017-08-16 15:01:51 -07:00
PushNotificationIOS Fix flowtype errors for PushNotificationIOS 2017-08-14 12:03:18 -07:00
RCTTest Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
ReactNative Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Renderer Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Sample Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
Settings Fix infinite recursion in RCTSettingsManager init 2017-08-09 09:39:40 -07:00
Share Flowify Process Color 2017-04-26 11:31:56 -07:00
Storage correctly order ASyncStorage 2017-02-21 15:18:40 -08:00
StyleSheet Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Text Upgrade fbsource/xplat/js to Flow v0.53.0 2017-08-17 18:45:01 -07:00
Utilities Cleanup stray markdown files, update contributing guidelines 2017-08-04 16:18:01 -07:00
Vibration Standardize project indentation settings on 2 spaces 2017-07-31 05:20:03 -07:00
WebSocket Force the debugger to disconnect before a bundle reload 2017-08-14 08:16:52 -07:00
fishhook Merge fishhook.xcodeproj in RCTWebSocket 2017-08-09 07:48:09 -07:00
polyfills Improve spacing in polyfill error messages 2017-08-10 03:56:01 -07:00
react-native Breaking - Remove AdSupportIOS 2017-07-26 13:32:41 -07:00
vendor gets Relay/Classic/Compat building 2017-07-24 21:39:00 -07:00
.eslintrc Disallow trailing commas in react-native-github 2017-08-17 16:20:04 -07:00
Promise.js Don't require prettyFormat in every single bundle. 2017-06-16 04:31:56 -07:00
promiseRejectionIsError.js RN: Cleanup OSS JS & Flow Declarations 2016-11-20 17:58:29 -08:00