onSnapshot hanging after killing iOS and restarting
Issue
Using onSnapshot works when first installing an iOS app with a release scheme, but once the app is killed and restarted a couple of times (1-2 on average), onSnapshot fails to return data or throw an error.
After extensive testing I found that setting includeMetadataChanges to true prevented this issue, but does lead to more events than desired.
useEffect(() => {
if (!uid || uid === '') {
log(`uid: ${uid}`);
setBoordUser(undefined);
return;
}
log(`uid: ${uid}`);
const subscriber = firestore()
.collection('users')
.doc(uid)
.onSnapshot(
(snapshot) => {
if (!snapshot || !snapshot.exists) {
setBoordUser(undefined);
} else {
setBoordUser(snapshot.data() as IBoordUser);
}
},
(error) => {
log(JSON.stringify(error));
},
);
return () => subscriber();
}, [uid]);
Project Files
Javascript
Click To Expand
package.json:
{
"version": "0.0.1",
"private": true,
"scripts": {
"android": "npx react-native run-android --verbose",
"android-release": "npx react-native run-android --variant=release",
"ios": "react-native run-ios",
"start": "react-native start",
"code-push": "ts-node ./bin/code-push.ts",
"bundle-android": "cd android && ./gradlew bundleRelease",
"start-android-release": "npx react-native run-android --variant=release",
"test": "jest",
"compile": "tsc --noEmit",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"dev-tools": "react-devtools",
"postinstall": "npx jetify"
},
"dependencies": {
"@expo/react-native-action-sheet": "^3.6.0",
"@invertase/react-native-apple-authentication": "^0.2.0",
"@react-native-community/cameraroll": "^1.5.2",
"@react-native-community/google-signin": "^4.0.0",
"@react-native-community/masked-view": "^0.1.7",
"@react-native-firebase/analytics": "6.7.1",
"@react-native-firebase/app": "6.7.1",
"@react-native-firebase/auth": "6.7.1",
"@react-native-firebase/database": "6.7.1",
"@react-native-firebase/dynamic-links": "6.7.1",
"@react-native-firebase/firestore": "6.7.1",
"@react-native-firebase/messaging": "6.7.1",
"@react-native-firebase/remote-config": "6.7.1",
"@react-native-firebase/storage": "6.7.1",
"@react-navigation/bottom-tabs": "^5.2.7",
"@react-navigation/native": "^5.1.4",
"@react-navigation/stack": "^5.2.9",
"@sentry/react-native": "^1.3.7",
"@terrylinla/react-native-sketch-canvas": "^0.8.0",
"@types/inquirer": "^6.5.0",
"@types/lodash": "^4.14.149",
"@types/react-native-vector-icons": "^6.4.5",
"@types/uuid": "^7.0.3",
"expo-keep-awake": "^8.1.0",
"expo-linear-gradient": "^8.1.0",
"gs": "^0.0.2",
"inquirer": "^7.1.0",
"lodash": "^4.17.15",
"react": "16.11.0",
"react-native": "0.62.0",
"react-native-agora": "^2.9.1-alpha.3",
"react-native-animatable": "^1.3.3",
"react-native-camera": "^3.22.0",
"react-native-code-push": "^6.2.0",
"react-native-confetti": "^0.1.0",
"react-native-draggable": "^3.1.0",
"react-native-draggable-flatlist": "^2.3.2",
"react-native-fs": "^2.16.6",
"react-native-gesture-handler": "^1.6.1",
"react-native-home-pressed": "^1.1.4",
"react-native-paper": "^3.6.0",
"react-native-reanimated": "^1.7.1",
"react-native-render-html": "^4.2.0",
"react-native-safe-area-context": "^0.7.3",
"react-native-screens": "^2.4.0",
"react-native-sound": "^0.11.0",
"react-native-unimodules": "^0.9.0",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "^9.1.3",
"reanimated-bottom-sheet": "^1.0.0-alpha.19",
"uuid": "^3.4.0"
},
"devDependencies": {
"@babel/core": "^7.6.2",
"@babel/runtime": "^7.6.2",
"@react-native-community/eslint-config": "^1.0.0",
"@types/jest": "^24.0.24",
"@types/react-native": "^0.62.0",
"@types/react-test-renderer": "16.9.2",
"@typescript-eslint/eslint-plugin": "^2.25.0",
"@typescript-eslint/parser": "^2.25.0",
"babel-jest": "^24.9.0",
"eslint": "^6.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.58.0",
"prettier": "^2.0.2",
"react-devtools": "^4",
"react-test-renderer": "16.11.0",
"ts-node": "^8.8.2",
"typescript": "^3.7.3"
},
"jest": {
"preset": "react-native",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json",
"node"
]
}
}
iOS
Click To Expand
ios/Podfile:
- [ ] I'm not using Pods
- [x] I'm using Pods and my Podfile looks like:
platform :ios, '10.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
require_relative '../node_modules/react-native-unimodules/cocoapods.rb'
def add_flipper_pods!
version = '~> 0.33.1'
pod 'FlipperKit', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitLayoutPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/SKIOSNetworkPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitUserDefaultsPlugin', version, :configuration => 'Debug'
pod 'FlipperKit/FlipperKitReactPlugin', version, :configuration => 'Debug'
end
# Post Install processing for Flipper
def flipper_post_install(installer)
installer.pods_project.targets.each do |target|
if target.name == 'YogaKit'
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.1'
end
end
end
end
target 'App' do
# Pods for App
pod 'GoogleSignIn', '~> 5.0.2'
pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"
pod 'RCTRequired', :path => "../node_modules/react-native/Libraries/RCTRequired"
pod 'RCTTypeSafety', :path => "../node_modules/react-native/Libraries/TypeSafety"
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/'
pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
pod 'React-Core/DevSupport', :path => '../node_modules/react-native/'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-Core/RCTWebSocket', :path => '../node_modules/react-native/'
pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'ReactCommon/callinvoker', :path => "../node_modules/react-native/ReactCommon"
pod 'ReactCommon/turbomodule/core', :path => "../node_modules/react-native/ReactCommon"
pod 'Yoga', :path => '../node_modules/react-native/ReactCommon/yoga', :modular_headers => true
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'react-native-agora', :path => '../node_modules/react-native-agora'
pod 'RNVectorIcons', :path => '../node_modules/react-native-vector-icons'
pod 'RNFS', :path => '../node_modules/react-native-fs'
pod 'react-native-cameraroll', :path => '../node_modules/@react-native-community/cameraroll'
target 'AppTests' do
inherit! :complete
# Pods for testing
end
use_native_modules!
use_unimodules!
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable these next few lines.
add_flipper_pods!
post_install do |installer|
flipper_post_install(installer)
end
end
target 'App-tvOS' do
# Pods for App-tvOS
target 'App-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
end
AppDelegate.m:
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <Firebase.h>
#import <CodePush/CodePush.h>
#import <UMCore/UMModuleRegistry.h>
#import <UMReactNativeAdapter/UMNativeModulesProxy.h>
#import <UMReactNativeAdapter/UMModuleRegistryAdapter.h>
#if DEBUG
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
static void InitializeFlipper(UIApplication *application) {
FlipperClient *client = [FlipperClient sharedClient];
SKDescriptorMapper *layoutDescriptorMapper = [[SKDescriptorMapper alloc] initWithDefaults];
[client addPlugin:[[FlipperKitLayoutPlugin alloc] initWithRootNode:application withDescriptorMapper:layoutDescriptorMapper]];
[client addPlugin:[[FKUserDefaultsPlugin alloc] initWithSuiteName:nil]];
[client addPlugin:[FlipperKitReactPlugin new]];
[client addPlugin:[[FlipperKitNetworkPlugin alloc] initWithNetworkAdapter:[SKIOSNetworkAdapter new]]];
[client start];
}
#endif
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
#if DEBUG
InitializeFlipper(application);
#endif
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
}
self.moduleRegistryAdapter = [[UMModuleRegistryAdapter alloc] initWithModuleRegistryProvider:[[UMModuleRegistryProvider alloc] init]];
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
moduleName:@"App"
initialProperties:nil];
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
}
- (NSArray<id<RCTBridgeModule>> *)extraModulesForBridge:(RCTBridge *)bridge
{
NSArray<id<RCTBridgeModule>> *extraModules = [_moduleRegistryAdapter extraModulesForBridge:bridge];
// You can inject any extra modules that you would like here, more information at:
// https://facebook.github.io/react-native/docs/native-modules-ios.html#dependency-injection
return extraModules;
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [CodePush bundleURL];
#endif
}
@end
Environment
Click To Expand
react-native info output:
System:
OS: macOS 10.15.4
CPU: (8) x64 Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz
Memory: 39.79 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
Yarn: 1.21.1 - /usr/local/bin/yarn
npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.4, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 25.0.2, 26.0.2, 26.0.3, 27.0.3, 28.0.3
System Images: android-27 | Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-27 | Google Play Intel x86 Atom, android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.5 AI-191.8026.42.35.5791312
Xcode: 11.4.1/11E503a - /usr/bin/xcodebuild
npmPackages:
react: 16.11.0 => 16.11.0
react-native: 0.62.0 => 0.62.0
- Platform that you're experiencing the issue on:
- [x] iOS
- [ ] Android
- [ ] iOS but have not tested behavior on Android
- [ ] Android but have not tested behavior on iOS
- [ ] Both
react-native-firebaseversion you're using that has this issue:e.g. 6.7.1
Firebasemodule(s) you're using that has the issue:Firestore
- Are you using
TypeScript?Y&3.7.3
- 👉 Check out
React Native FirebaseandInvertaseon Twitter for updates on the library.
I'm experiencing a similar thing. When I restart the app on iOS, it hangs and doesn't return an error or anything. But when I reload the app after that initial launch, it starts working normally.
Hello 👋, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?
This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.
I think this is happening to me also
This is probably going to be an upstream issue in the underlying SDK - have you searched there @zomars to see if they have anything relevant? https://github.com/firebase/firebase-ios-sdk
@mikehardy I didn't found anything there, but it may be related to this: https://firebase.google.com/support/release-notes/ios#cloud-firestore
Cloud Firestore
Fixed an issue that may have prevented the client from connecting to the backend immediately after a user signed in.
I'll try to manually upgrade the SDK and report back.
Sounds like a plan - for reference we are using 6.27 in the test suite now and I'm using it locally without issue, so it should be safe though of course test things to make sure. I actually haven't ever suffered a regression in the entire 6.x series so I update pretty confidently whenever it comes out but now that I've said that the next one might bite me. Cheers
I've followed these steps:
- Added
$FirebaseSDKVersion = '6.27.0'to my Podfile - Ran
pod update - Ran
react-native run-ios
And can confirm that the onSnapshot callback is running properly now.
fantastic news, thanks for testing and reporting success for future people
It seems we're still using 6.25.0?(https://github.com/invertase/react-native-firebase/blob/master/packages/app/package.json#L70) Shouldn't we update?
Also, for anyone else who stumbles upon this and is wondering exactly how up up the firebase version on their own, this is what Mike was talking about: https://github.com/invertase/react-native-firebase/blob/65042d08ed1233cfdb35b6c2d51d87be2d305d3c/tests/ios/Podfile#L7
Test project is already on 6.27 yes, my project as well. Works fine, just they issue them about every 2 weeks upstream and doing the PRs here lags. Any PR to update test project (already done in this case) and Pod dependencies would probably be met with trumpet serenade and angel song :-)
This bug is still here. I've tested 11.1.0 and almost latest (12.8.0) firebase versions. Only adding "includeMetadataChanges: true" helped. Maybe this moment is already described but this bug exists only for release scheme. Any attpets to get this bug with debug scheme weren't succeded. @dsessoms @mikehardy Does anybody know how to solve this issue with no adding "inclueMetadata..."?
I do not know, this looks like it might need a native reproduction to figure out roughly what layer it is.
You might start with a clean reproduction in a react-native-firebase-only app built from https://github.com/mikehardy/rnfbdemo/commits/master/make-demo.sh with nothing but an index.js/App.js to prove it happens with no other modules, if so then I'd try native
The native issues list (for a quick look) is https://github.com/firebase/firebase-ios-sdk/issues and a template to try a native reproduction is https://github.com/firebase/quickstart-ios/tree/master/firestore - along with our code here might get a native reproduction pretty quickly. I can't see how this would be at the react-native-firebase level so that's the likely path forward.
@mikehardy Thank you for instructions. I'll try to reproduce it via "make-demo"