Skip to content

feat(firestore): support serverTimestamps option on snapshot listeners#993

Open
robingenz wants to merge 2 commits into
mainfrom
feat/issue-985-server-timestamps
Open

feat(firestore): support serverTimestamps option on snapshot listeners#993
robingenz wants to merge 2 commits into
mainfrom
feat/issue-985-server-timestamps

Conversation

@robingenz
Copy link
Copy Markdown
Member

Summary

  • Adds a new serverTimestamps?: 'estimate' | 'previous' | 'none' option on SnapshotListenerOptions, applied to addDocumentSnapshotListener, addCollectionSnapshotListener, and addCollectionGroupSnapshotListener on Web, Android, and iOS.
  • Threads the value through to the underlying Firebase SDK so pending server timestamps in unacknowledged writes can be returned as null (default), the client-estimated time, or the previous value.

Test plan

  • Document listener returns null for a pending serverTimestamp() field with default settings, and a Timestamp when serverTimestamps: 'estimate' is set (Web, Android, iOS).
  • Same verification for collection and collection-group listeners.
  • Unknown / unset value still resolves to 'none' (no crash).

Closes #985

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
Copilot AI review requested due to automatic review settings May 25, 2026 08:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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' to SnapshotListenerOptions.
  • Web: passes serverTimestamps into DocumentSnapshot.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.

Comment thread packages/firestore/src/web.ts
Comment thread packages/firestore/src/web.ts
Comment thread packages/firestore/src/web.ts
- 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)
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 25, 2026

Open in StackBlitz

@capacitor-firebase/analytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/analytics@993

@capacitor-firebase/app

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app@993

@capacitor-firebase/app-check

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/app-check@993

@capacitor-firebase/authentication

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/authentication@993

@capacitor-firebase/crashlytics

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/crashlytics@993

@capacitor-firebase/firestore

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/firestore@993

@capacitor-firebase/functions

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/functions@993

@capacitor-firebase/messaging

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/messaging@993

@capacitor-firebase/performance

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/performance@993

@capacitor-firebase/remote-config

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/remote-config@993

@capacitor-firebase/storage

npm i https://pkg.pr.new/capawesome-team/capacitor-firebase/@capacitor-firebase/storage@993

commit: 8bee41b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(firestore): support different pending serverTimestamps behaviors

2 participants