fix(client): use 'estimate' serverTimestamps default in query/queryGroup - #123
Open
detail-app[bot] wants to merge 1 commit into
Open
detail-app[bot] wants to merge 1 commit into
detail-app[bot] wants to merge 1 commit into
Conversation
|
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.
Detail bug report: View on Detail
Bug
The client
FirestoreService'srunQueryhelper (backsqueryandqueryGroup) calledqueryDoc.data()with no options, falling back to the Firebase client SDK defaultserverTimestamps: 'none'. With that default, pending server timestamps — a document just written withFieldValue.serverTimestamp()while offline and read from cache — decode asnull.Every other read in the service (
get,streamDoc,streamQuery,streamQueryGroup) uses the library-wide'estimate'default via thedataOptionshelper, so reading a just-written document through different methods disagreed:repo.getById()andrepo.queryStream()succeeded whilerepo.query()/repo.group.query()raised aSchemaError(thenulltimestamp fails the model's required-timestamp schema, e.g.Firestore.DateTimeInsert). Introduced in 6ee2bc4, which addeddataOptionsbut applied it only to the new streaming methods, leaving the pre-existingqueryon the SDK default.Fix
runQuerynow callsqueryDoc.data(dataOptions()), restoring the documented'estimate'default and consistency with the other reads.query/queryGroupdon't exposeFirestoreDataOptionson theFirestoreServiceinterface, so the default is applied viadataOptions()with no argument — matching the existing contract while fixing the asymmetry.The admin copy is intentionally left unchanged:
@google-cloud/firestore'sdata()takes noSnapshotOptionsand always returns resolved timestamps, so there is no pending-timestamp state to mishandle.Testing
query,queryGroup, andgetpassserverTimestamps: 'estimate'intosnapshot.data(). Thequery/queryGroupcases fail without the fix (the option isundefinedinstead of'estimate') and pass with it; thegetcases anchor the cross-method consistency. (packages/client/src/lib/firestore/firestore-service.spec.ts)pnpm nx affected -t lint test build; the client Firestore specs are green (34/34); the adminfirestore-service.tsis untouched.firebase/firestoreSDK: on the online happy path the four read methods agree (the server resolves the timestamp immediately so the bug is not observable while online) — confirms no regression.failed-precondition); under jsdom + an IndexedDB shim, persistence enables but the SDK's offline write path hangs. The added unit tests cover the contract via the real service code with the SDK'sdata(options)pending-timestamp behavior simulated at the snapshot boundary — the only seam where'none'returnsnulland'estimate'returns aTimestamp.Closes #104
Automatic Fixes PRs can be configured here.