jhen0409 / react-native-debugger

The standalone app based on official debugger of React Native, and includes React Inspector / Redux DevTools
MIT License
10.35k stars 810 forks source link

`showAsyncStorageContentInDev()` shows stale content #435

Closed marhaupe closed 4 years ago

marhaupe commented 4 years ago

React Native Debugger app version: 0.10.4; reproducible with master React Native version: 0.61.2 Platform: iOS Is real device of platform: yes Operating System: macOS 10.14.6

When invoking showAsyncStorageContentInDev() in the console, you receive the content of the current AsyncStorage. After programmatically changing the content of the AsyncStorage and after invoking showAsyncStorageContentInDev() again, you receive the same content of the AsyncStorage you received earlier. This should not happen.

After some digging, I noticed the following differences in the resolution for RCTAsyncStorage in this library: https://github.com/jhen0409/react-native-debugger/blob/370205764045016b796916f33fdfaeb7b89ad5d1/app/worker/asyncStorage.js#L25-L30

and in the official react-native-async-storage library (https://github.com/react-native-community/async-storage/blob/b04ffbf1b80bdf5295cb36c21fc5ca62a7333e3c/lib/AsyncStorage.js#L16-L19):

const RCTAsyncStorage =
  NativeModules.RNC_AsyncSQLiteDBStorage ||
  NativeModules.RNCAsyncStorage ||
  NativeModules.PlatformLocalStorage;

On my device, these differences lead to a different NativeModule being used. This lib uses NativeModules.AsyncLocalStorage, while react-native-community uses NativeModules.RNCAsyncStorage. Changing the implementation of this lib to match the 'official' one fixes these issues on my device. Let me know if you're interested in a pull request adressing this issue that includes this fix.

jhen0409 commented 4 years ago

Thanks for report! PRs are welcome.