feat(firestore): support serverTimestamps option on snapshot listeners#993
Open
robingenz wants to merge 2 commits into
Open
feat(firestore): support serverTimestamps option on snapshot listeners#993robingenz wants to merge 2 commits into
robingenz wants to merge 2 commits into
Conversation
Expose Firestore's pending server timestamp behavior ('estimate' |
'previous' | 'none') as an option on addDocumentSnapshotListener,
addCollectionSnapshotListener, and addCollectionGroupSnapshotListener
on Web, Android, and iOS. Defaults to 'none' (current behavior).
Closes #985
There was a problem hiding this comment.
Pull request overview
This PR adds cross-platform support for configuring how pending Firestore serverTimestamp() fields are represented in snapshot listener results, by introducing a serverTimestamps option and threading it through Web/Android/iOS implementations.
Changes:
- Adds
serverTimestamps?: 'estimate' | 'previous' | 'none'toSnapshotListenerOptions. - Web: passes
serverTimestampsintoDocumentSnapshot.data(...)for document/collection/collection-group snapshot listeners. - Android/iOS: maps the string option to the Firebase SDK’s server timestamp behavior and uses it when materializing snapshot data in result objects.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/firestore/src/web.ts | Forwards serverTimestamps into Firestore Web SDK data() calls for listener snapshots. |
| packages/firestore/src/definitions.ts | Extends listener option types with serverTimestamps and documents its behavior. |
| packages/firestore/ios/Plugin/FirebaseFirestorePlugin.swift | Reads serverTimestamps from plugin calls and passes it into listener option objects. |
| packages/firestore/ios/Plugin/FirebaseFirestoreHelper.swift | Adds a helper to map string values to ServerTimestampBehavior. |
| packages/firestore/ios/Plugin/FirebaseFirestore.swift | Threads server timestamp behavior into listener result creation. |
| packages/firestore/ios/Plugin/Classes/Results/GetDocumentResult.swift | Uses data(with:) using the configured server timestamp behavior. |
| packages/firestore/ios/Plugin/Classes/Results/GetCollectionResult.swift | Uses data(with:) using the configured server timestamp behavior. |
| packages/firestore/ios/Plugin/Classes/Results/GetCollectionGroupResult.swift | Uses data(with:) using the configured server timestamp behavior. |
| packages/firestore/ios/Plugin/Classes/Options/AddDocumentSnapshotListenerOptions.swift | Stores and exposes the server timestamp behavior string from JS. |
| packages/firestore/ios/Plugin/Classes/Options/AddCollectionSnapshotListenerOptions.swift | Stores and exposes the server timestamp behavior string from JS. |
| packages/firestore/ios/Plugin/Classes/Options/AddCollectionGroupSnapshotListenerOptions.swift | Stores and exposes the server timestamp behavior string from JS. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/FirebaseFirestorePlugin.java | Reads serverTimestamps from plugin calls and passes it into listener option objects. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/FirebaseFirestoreHelper.java | Adds a helper to map string values to DocumentSnapshot.ServerTimestampBehavior. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/FirebaseFirestore.java | Threads server timestamp behavior into listener result creation. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/classes/results/GetDocumentResult.java | Uses getData(serverTimestampBehavior) when building JS results. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/classes/results/GetCollectionResult.java | Uses getData(serverTimestampBehavior) when building JS results. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/classes/options/AddDocumentSnapshotListenerOptions.java | Adds storage/getter for the serverTimestamps string. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/classes/options/AddCollectionSnapshotListenerOptions.java | Adds storage/getter for the serverTimestamps string. |
| packages/firestore/android/src/main/java/io/capawesome/capacitorjs/plugins/firebase/firestore/classes/options/AddCollectionGroupSnapshotListenerOptions.java | Adds storage/getter for the serverTimestamps string. |
| .changeset/firestore-server-timestamps.md | Declares a minor version bump for the new Firestore listener option. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Normalize serverTimestamps on Web to match native fall-back behavior - Remove unused Nullable import in GetDocumentResult.java - Reformat definitions.ts with prettier 3.4.2 (pinned CI version)
@capacitor-firebase/analytics
@capacitor-firebase/app
@capacitor-firebase/app-check
@capacitor-firebase/authentication
@capacitor-firebase/crashlytics
@capacitor-firebase/firestore
@capacitor-firebase/functions
@capacitor-firebase/messaging
@capacitor-firebase/performance
@capacitor-firebase/remote-config
@capacitor-firebase/storage
commit: |
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
serverTimestamps?: 'estimate' | 'previous' | 'none'option onSnapshotListenerOptions, applied toaddDocumentSnapshotListener,addCollectionSnapshotListener, andaddCollectionGroupSnapshotListeneron Web, Android, and iOS.null(default), the client-estimated time, or the previous value.Test plan
nullfor a pendingserverTimestamp()field with default settings, and aTimestampwhenserverTimestamps: 'estimate'is set (Web, Android, iOS).'none'(no crash).Closes #985