react-native-firebase icon indicating copy to clipboard operation
react-native-firebase copied to clipboard

[🐛] Bug Report Title - promise is pending forever only on ios device

Open antontelichenko opened this issue 3 years ago • 3 comments

Issue

Have a problem when I'm trying to make a request to the firestore, but my promise is pending forever only on ios device. query code

firestore()
        .collection('fcmtokens')
        .add({
          token: token,
        })
        .then(data => console.log('data after query', data))
        .catch(e => {
          console.log('error', e);
        });

also sometimes it works for ios emulator, and device, but it happens very rarely

Project Files

Javascript

Click To Expand

package.json:

{
  "name": "webviewapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint .",
    "clean": "react-native-clean-project"
  },
  "dependencies": {
    "@react-native-async-storage/async-storage": "^1.15.14",
    "@react-native-firebase/app": "^13.1.0",
    "@react-native-firebase/database": "^13.1.0",
    "@react-native-firebase/firestore": "^13.1.0",
    "@react-native-firebase/messaging": "^13.1.0",
    "react": "17.0.2",
    "react-native": "0.66.3",
    "react-native-clean-project": "^3.6.7",
    "react-native-webview": "^11.15.0"
  },
  "devDependencies": {
    "@babel/core": "^7.16.0",
    "@babel/runtime": "^7.16.3",
    "@react-native-community/eslint-config": "^3.0.1",
    "babel-jest": "^27.4.2",
    "eslint": "^8.3.0",
    "jest": "^27.4.3",
    "metro-react-native-babel-preset": "^0.66.2",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • [ ] I'm not using Pods
  • [x] I'm using Pods and my Podfile looks like:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '11.0'

target 'voncoinwebviewapp' do
  config = use_native_modules!

  use_react_native!(
    :path => config[:reactNativePath],
    # to enable hermes on iOS, change `false` to `true` and then install pods
    :hermes_enabled => false
  )

  target 'voncoinwebviewappTests' do
    inherit! :complete
    # Pods for testing
  end

  # Enables Flipper.
  #
  # Note that if you have use_frameworks! enabled, Flipper will not work and
  # you should disable the next line.
  # use_flipper!()

  # post_install do |installer|
  #   react_native_post_install(installer)
  #   __apply_Xcode_12_5_M1_post_install_workaround(installer)
  # end
end

AppDelegate.m:

#import "AppDelegate.h"

#import <Firebase.h>
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

#ifdef FB_SONARKIT_ENABLED
#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
{
#ifdef FB_SONARKIT_ENABLED
  InitializeFlipper(application);
#endif

  [FIRApp configure];
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"webviewapp"
                                            initialProperties:nil];

  if (@available(iOS 13.0, *)) {
      rootView.backgroundColor = [UIColor systemBackgroundColor];
  } else {
      rootView.backgroundColor = [UIColor whiteColor];
  }

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

@end


Android

Click To Expand

Have you converted to AndroidX?

  • [ ] my application is an AndroidX application?
  • [ ] I am using android/gradle.settings jetifier=true for Android compatibility?
  • [ ] I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->

Environment

Click To Expand

react-native info output:

 OUTPUT GOES HERE
  • Platform that you're experiencing the issue on:
    • [ ] iOS
    • [ ] Android
    • [ ] iOS but have not tested behavior on Android
    • [ ] Android but have not tested behavior on iOS
    • [ ] Both
  • react-native-firebase version you're using that has this issue:
    • e.g. 5.4.3
  • Firebase module(s) you're using that has the issue:
    • e.g. Instance ID
  • Are you using TypeScript?
    • Y/N & VERSION

antontelichenko avatar Dec 15 '21 09:12 antontelichenko

We're going to need a reproduction for this - an App.js we can drop in a skeleton (like from https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh) https://stackoverflow.com/help/minimal-reproducible-example If this were widespread and happening in the module we would likely have heard about it before, so my hunch is there is something more going on with this particular project or this particular device.

mikehardy avatar Dec 15 '21 12:12 mikehardy

here is an App.js

import React, {useEffect, useState} from 'react';
import type {Node} from 'react';

import {WebView} from 'react-native-webview';
import firestore from '@react-native-firebase/firestore';
import {
  requestUserPermission,
  notificationListener,
} from './src/firebaseMessagingServices';

const App: () => Node = () => {
  const [token, setToken] = useState('');
  const [link, setLink] = useState(
    'https://google.com,
  );

  useEffect(() => {
    async function checkPermissions() {
      setToken(await requestUserPermission());
      notificationListener(setLink);
    }
    checkPermissions();
  }, []);

  useEffect(() => {
    function setFCMTokenToFirestore() {
      firestore()
        .collection('fcmtokens')
        .add({
          token: token,
        })
        .then(data => console.log('data after query', data))
        .catch(e => {
          console.log('error', e);
        });
    }
    token && setFCMTokenToFirestore();
  }, [token]);

  return (
    <>
      <WebView
        startInLoadingState={true}
        androidLayerType={'software'}
        scalesPageToFit={true}
        originWhitelist={['*']}
        source={{uri: link}}
      />
    </>
  );
};

export default App;

or I need to send something else?

antontelichenko avatar Dec 15 '21 12:12 antontelichenko

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.

stale[bot] avatar Apr 18 '22 18:04 stale[bot]

@mikehardy @antontelichenko Any updates on this. Like patch or some other solution.

jeet-dhandha-lio avatar Oct 13 '22 12:10 jeet-dhandha-lio

Sorry - received a repro but is not exactly minimal (it has a WebView? What's the webview do? Where is the code being imported from elsewhere? it is not self-contained + minimal in other words) @jeet-dhandha-lio if you trim the repro to be actually minimal and you can drop it in a current https://github.com/mikehardy/rnfbdemo/blob/main/make-demo.sh result and reproduce, I can try to take a look

Please carefully note all the versions in use when you reproduce - that is what version of simulator / real device iOS is in use, the make-demo script means the rest will be known versions

mikehardy avatar Oct 13 '22 17:10 mikehardy

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 attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

github-actions[bot] avatar Dec 05 '22 19:12 github-actions[bot]