bug(firestore): Timestamp values
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)
- build project
- run on local web server
- run on an iOS device
- 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.
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!
Thank you for reporting this issue! Would you be willing to create a PR with your idea? I would then take a closer look.
Sure thing, @robingenz . I'll see if I can get that together, this morning.
@robingenz Could you please provide any updates on this matter or offer an estimated timeframe for resolving the issue? Thank you.
- #564
- #475
@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 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 No, this should be another issue. Please create a separate bug report.
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?
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.