capacitor-firebase icon indicating copy to clipboard operation
capacitor-firebase copied to clipboard

bug(firestore): Timestamp values

Open Paganiniana opened this issue 2 years ago • 22 comments

Plugin(s)

  • [ ] Analytics
  • [ ] App
  • [ ] App Check
  • [ ] Authentication
  • [ ] Crashlytics
  • [X] Cloud Firestore
  • [ ] Cloud Messaging
  • [ ] Performance
  • [ ] Remote Config

Did you test the latest version?

  • [X] I use the latest version

Platform(s)

  • [ ] Android
  • [X] iOS
  • [ ] Web

Current behavior

If I read a document using the FirebaseFirestore.getDocument method, its snapshot.data object is completely missing any value that resolves as a Firestore Timestamp value. For example, a document of the following format in Firebase ...

const docData = {
     author: "Some Name",
     description: "Some description",
     creationDate: <some timestamp>,
}

... is returned as ...

const docData = {
     author: "Some Name",
     description: "Some description",
}

Expected behavior

I would expect that any snapshot.data value has certain values in Firestore, it this method would return those values as part of its resolved object structure.

Reproduction

https://github.com/Paganiniana/capawesome-bug-reproduction

Steps to reproduce

(See the readme)

  1. build project
  2. run on local web server
  3. run on an iOS device
  4. observe difference in console logs

Other information

No response

Capacitor doctor

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 5.5.0 @capacitor/core: 5.5.0 @capacitor/android: 5.5.0 @capacitor/ios: 5.5.0

Installed Dependencies:

@capacitor/android: not installed @capacitor/cli: 5.5.0 @capacitor/ios: 5.5.0 @capacitor/core: 5.5.0

[success] iOS looking great! 👌

Before submitting

  • [X] I understand that incomplete issues (e.g. without reproduction) are closed.

Paganiniana avatar Oct 23 '23 21:10 Paganiniana

In poking around the codebase, I've narrowed down the problem to the FirebaseFirestoreHelper.swift file. It seems the createJSValue method returns nil for instances of Timestamp. I'm manually marking its type and passing up its value as a second/nano second pair. In the JS layer, I'm passing these to the timestamp constructor, making it work just like the web client. If we could make these changes in firestore/src/index.ts and wrap the necessary read/write methods to pass this information back and forth from the native/web layers, that would be great!

Screenshot 2023-10-23 at 4 03 50 PM

Paganiniana avatar Oct 23 '23 23:10 Paganiniana

Thank you for reporting this issue! Would you be willing to create a PR with your idea? I would then take a closer look.

robingenz avatar Oct 24 '23 05:10 robingenz

Sure thing, @robingenz . I'll see if I can get that together, this morning.

Paganiniana avatar Oct 24 '23 13:10 Paganiniana

@robingenz Could you please provide any updates on this matter or offer an estimated timeframe for resolving the issue? Thank you.

  1. #564
  2. #475

SureshKumarToverto avatar Feb 26 '24 11:02 SureshKumarToverto

@SureshKumarToverto As already mentioned in https://github.com/capawesome-team/capacitor-firebase/issues/564#issuecomment-1952422981, this is currently a bug in Capacitor (see https://github.com/ionic-team/capacitor/issues/7252). I have to wait until it's fixed.

robingenz avatar Feb 26 '24 13:02 robingenz

@robingenz does this same bug also affect geopoints? we store both timestamps and geopoints in our firestore db, everything comes back fine when testing in the browser, but when we compile into a native iOS app and test on the device, neither timestamps/geopoints come back

johnmckay-reward avatar Apr 08 '24 11:04 johnmckay-reward

@johnmckay-reward No, this should be another issue. Please create a separate bug report.

robingenz avatar Apr 09 '24 07:04 robingenz

Is there a workaround for this bug while waiting for the capacitor team to fix https://github.com/ionic-team/capacitor/issues/7252, or should I switch to storing my dates as strings as opposed to the Timestamp type in firestore to avoid this issue?

mdean808 avatar May 20 '24 07:05 mdean808

No, there is currently no workaround. I have another idea on how to solve this, but of course I would prefer the problem to be solved in the Capacitor Core. I currently save all timestamps as ISO 8601 strings.

robingenz avatar May 20 '24 07:05 robingenz