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

Re: Firestore call causes folly::toJson error

Open SukhKalsi opened this issue 8 years ago β€’ 25 comments

Issue

Hello. I'm trying to use this library in conjunction with react-native-maps. The later package (which is in the community react repos!) is insistent on using Cocoapods and in fact doesn't work using react-native link (reference: https://github.com/react-community/react-native-maps/blob/master/docs/installation.md )... which sods law is one of the unrecommended ways to use this library... Bit of a predicment i decided to follow the Cocoapods route as I've used this Firebase library on couple of projects this way and haven't noticed any issues... till now...

So i can get the app to run, the maps to load and even initially get data from the Firebase Firestore database (even though it gives me red screen of death - see below). Trying to figure out where this error is coming from, it simply is this one line of code of me just getting reference of one of collection in the Firestore DB:

const { firestore: firestoreSingleton } = firebase
const firestore = firestoreSingleton()
const ref = firestore.collection('SomeCollection')

export const getSomething = async () => {
  const data = await ref.get() // THIS LINE SHOWS THE RED SCREEN OF DEATH
  return data
}

This is my pod file:

target 'App' do
  rn_path = '../node_modules/react-native'
  rn_maps_path = '../node_modules/react-native-maps'

  # See http://facebook.github.io/react-native/docs/integration-with-existing-apps.html#configuring-cocoapods-dependencies
  pod 'yoga', path: "#{rn_path}/ReactCommon/yoga/yoga.podspec"
  pod 'React', path: rn_path, subspecs: [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket',
  ]

  # React Native third party dependencies podspecs
  pod 'DoubleConversion', :podspec => "#{rn_path}/third-party-podspecs/DoubleConversion.podspec"
  pod 'glog', :podspec => "#{rn_path}/third-party-podspecs/glog.podspec"
  # If you are using React Native <0.54, you will get the following error:
  # "The name of the given podspec `GLog` doesn't match the expected one `glog`"
  # Use the following line instead:
  #pod 'GLog', :podspec => "#{rn_path}/third-party-podspecs/GLog.podspec"
  pod 'Folly', :podspec => "#{rn_path}/third-party-podspecs/Folly.podspec"

  # react-native-maps dependencies
  pod 'react-native-maps', path: rn_maps_path
  # pod 'react-native-google-maps', path: rn_maps_path  # Remove this line if you don't want to support GoogleMaps on iOS
  # pod 'GoogleMaps'  # Remove this line if you don't want to support GoogleMaps on iOS
  # pod 'Google-Maps-iOS-Utils' # Remove this line if you don't want to support GoogleMaps on iOS

  # Firebase
  pod 'Firebase/Core', '~> 4.13.0'
  pod 'Firebase/Firestore'
  # pod 'Fabric', '~> 1.7.6't
  # pod 'Crashlytics', '~> 3.10.1'

  pod 'RNFirebase', :path => '../node_modules/react-native-firebase/ios'
  # pod 'RNFS', :path => '../node_modules/react-native-fs'
  pod 'react-native-fast-image', :path => '../node_modules/react-native-fast-image'
  pod 'RNSVG', :path => '../node_modules/react-native-svg'
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    if target.name == 'react-native-google-maps'
      target.build_configurations.each do |config|
        config.build_settings['CLANG_ENABLE_MODULES'] = 'No'
      end
    end
    if target.name == "React"
      target.remove_from_project
    end
  end
end

Environment

  1. Application Target Platform: iOS only.

  2. Development Operating System: macOS High Sierra

  3. Build Tools: Xcode Version 9.4

  4. React Native version: 0.54.4

  5. React Native Firebase Version: 4.1.0

  6. Firebase Module: Core & Firestore

  7. Are you using typescript? No

This is the red screen of death error:

simulator screen shot - iphone x - 2018-07-30 at 15 18 17

SukhKalsi avatar Jul 30 '18 14:07 SukhKalsi

Same problem, appears to be related to data coming down the line. Issue appears on both Android and iOS for me. Still trying to work out exactly the cause. Did you get to the bottom of it?

rknell avatar Aug 02 '18 05:08 rknell

OK! Solved it for me!!!

Turns out I had a text field with the word Infinity... which got interpreted as the numeric value... Inifinity... changed it to a string in the firestore console and all is good! Hope you solve your issue.

rknell avatar Aug 02 '18 06:08 rknell

@rknell Sounds an interesting one! Could you take a screenshot of exactly what you mean by the 'word Infinity' in the console?

@SukhKalsi could you show us what data you have on the ref, on the console?

Ehesp avatar Aug 02 '18 09:08 Ehesp

Thanks for the insight @rknell - glad you got it resolved πŸ‘ deffo a data parsing issue for sure, unfortunately i have a lot of data in this Firestore (several hundred collections with each collection having about 25+ fields πŸ™ˆ) -> inherited from an existing app so also need to be careful what i do (annoyingly Firestore doesn't have a export feature)

Interestingly once the initial request has gone out the Red Screen of Death is slightly different but points to JSON issue...

simulator screen shot - iphone x - 2018-08-02 at 19 22 49

Will dig into the source and see what I can find

SukhKalsi avatar Aug 02 '18 19:08 SukhKalsi

@Ehesp This is what I mean by "Infinity"

So this will work no problems (as it should!) screen shot 2018-08-03 at 9 03 46 am

This however will crash the app when it tries to read the record: screen shot 2018-08-03 at 9 03 57 am

You will notice that the console recognises "Infinity" as a number if I don't type it correctly: screen shot 2018-08-03 at 9 04 03 am

@SukhKalsi Yeah I was very lucky, only having about 40 records to dig through. My break was in a nested collection though which complicated the issue. To find it I put a limit on the data, and did some filtering to see exactly when it broke. If you could load each record, one at a time, and log it out to console as you go, you might be able to track down the offending record too.

I didn't get the red screen afterwards, so there is a chance your data may not be "Inifinity" but NaN as per the first error. The only reason this occurred in the first place is because there is a damn company around here called infinity!

rknell avatar Aug 02 '18 23:08 rknell

So I managed to decipher what was happening by using the debugging tools in Xcode. My issue is pretty similar to yours @rknell but as you suggested was actually related to NaN values being populated (how the data go in like this is beyond me).

Due to the volume of data (which i certainly wasn't going to cleanse!), I made the following addition here:

    if (!value || [[value description].lowercaseString isEqual: @"nan"]) {
        typeMap[@"type"] = @"null";
    } 

Within this line: https://github.com/invertase/react-native-firebase/blob/master/ios/RNFirebase/firestore/RNFirebaseFirestoreDocumentReference.m#L191-L192

Whether thats worthy of going in as a PR is up to the peeps managing this project πŸ™‚

SukhKalsi avatar Aug 03 '18 00:08 SukhKalsi

@SukhKalsi @rknell would you be able to test if this is an issue on Android also?

I can potentially push up a small change to iOS to handle these correctly so you don't have to do any data changes. (@SukhKalsi thanks for the suggested change also)


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Aug 04 '18 04:08 Salakar

I can 100% confirm it's also an Android issue, iOS was where it was reported for me. But Android was what I used to test it was resolved

On Sat., 4 Aug. 2018, 2:57 pm Michael Diarmid, [email protected] wrote:

@SukhKalsi https://github.com/SukhKalsi @rknell https://github.com/rknell would you be able to test if this is an issue on Android also?

I can potentially push up a small change to iOS to handle these correctly so you don't have to do any data changes. (@SukhKalsi https://github.com/SukhKalsi thanks for the suggested change also)

Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

β€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/invertase/react-native-firebase/issues/1357#issuecomment-410423745, or mute the thread https://github.com/notifications/unsubscribe-auth/AFmlbdSvIzpkBuBOoBBFvWutM_o9VcJmks5uNSmagaJpZM4Vmifq .

rknell avatar Aug 04 '18 04:08 rknell

@rknell ok cool, thanks for confirming. I'll look into adding support for these in a moment. πŸ‘

Salakar avatar Aug 04 '18 05:08 Salakar

Thanks for looking into this @Salakar :) For this project I'm only targeting iOS (Android app was already built) so I've pretty much neglected the state of Android. I can try get a small project in Android with the same dataset (I would assume it'll behave the same - as @rknell confirmed on his project with Infinity issue).

SukhKalsi avatar Aug 04 '18 17:08 SukhKalsi

@rknell also fixed searching for a Infinity or NaN value on a Number field

cristiam86 avatar Aug 21 '18 14:08 cristiam86

Any solutions for Android? With changed from @SukhKalsi, it works. But I don't know how to update in Android. Thanks.

tiendn avatar Sep 22 '18 15:09 tiendn

Support for NaN and Infinity numbers has landed for Android and IOS today - on v5.0.0-rc5 - this will work with the JS equivalents of NaN/Infinity instead of null or crashing.

Thanks


Loving react-native-firebase and the support we provide? Please consider supporting us with any of the below:

Salakar avatar Sep 24 '18 01:09 Salakar

I'm on [email protected] and pod 'Firebase/Firestore', 5.15.0' and my app crashes when I try to load -Infinity from Firestore. It took me good hours to figure this out.

Care to verify and fix that so other people save some hours? Crashes only on iOS. I was testing in "production" mode only.

damienix avatar Mar 11 '19 16:03 damienix

I have same issue when fetch firebase configs with getValues method. Crash on android version 4.4 :( Have any suggest to solve it?

sinhpn92 avatar Jun 25 '19 03:06 sinhpn92

@sinhpn92 can you confirm that the problem is a β€˜-Infinity’ value? That is, this is still crashing, and on a version after v5? If so, maybe we need to reopen

mikehardy avatar Jun 25 '19 03:06 mikehardy

@mikehardy Exactly. It's infinity value. I'm using version 5.2.5. I have added this code to solve it:

Double doubleValue = null;
    try {
      doubleValue = value.asDouble();
      if (Double.isInfinite(doubleValue)) doubleValue = null;
    } catch (Exception e) { }

sinhpn92 avatar Jun 25 '19 04:06 sinhpn92

Dang - @Salakar @Ehesp looks like both of you touched on this one, and it’s a zombie? See the most recent comments

mikehardy avatar Jun 25 '19 04:06 mikehardy

I'll check this out on Firestore. Not sure how Infinity works on remote config? Isn't it just strings (+ empty strings).

Ehesp avatar Jun 25 '19 17:06 Ehesp

Okay so just confirmed setting -Infinity is not handled at all on v5. On v6 I have implemented this (still WIP) and added tests to cover everything.

Also unrelated but found another bug, setting new Date() as a value causes it to be an empty object on Firestore, which now is handled as a Timestamp as the web SDK does.

I can backport to a v5 release at some point.

Ehesp avatar Jun 26 '19 10:06 Ehesp