fix(firestore): handle DocumentReference fields in web deserializer#981
Merged
Conversation
Reading a document containing a `DocumentReference` field on web caused
`RangeError: Maximum call stack size exceeded` because `deserializeData`
had no branch for `DocumentReference` and fell through to the generic
object branch, which recursed into the cyclic `_firestore` getter.
Adds dedicated handling that produces a
`{ __type__: 'documentReference', id, path }` marker (mirroring
`Timestamp`/`GeoPoint`) and the symmetric `serializeMarker` case so a
deserialized reference can be written back.
Close #975
There was a problem hiding this comment.
Pull request overview
Fixes a RangeError: Maximum call stack size exceeded in the Firestore web shim when reading documents containing DocumentReference fields. The web deserializeData previously had no branch for DocumentReference and recursed into the cyclic _firestore getter via the generic object branch. This PR adds dedicated (de)serialization for DocumentReference, mirroring the existing Timestamp / GeoPoint pattern, and exposes a corresponding FirestoreDocumentReference marker interface.
Changes:
- Add a
DocumentReferencebranch indeserializeDatathat returns a{ __type__: 'documentReference', id, path }marker. - Add the symmetric
'documentReference'case inserializeMarkerto round-trip the marker viadoc(getFirestore(), marker.path). - Add the
FirestoreDocumentReferencemarker interface indefinitions.ts.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/firestore/src/web.ts | Imports DocumentReference from firebase/firestore and adds the deserialize/serialize branches for the new marker. |
| packages/firestore/src/definitions.ts | Adds the new FirestoreDocumentReference marker interface (__type__: 'documentReference', id, path). |
| .changeset/firestore-web-document-reference.md | Adds a patch-level changeset describing the fix. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@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: |
17 tasks
5 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
DocumentReferencefield on web causedRangeError: Maximum call stack size exceededbecausedeserializeDatahad no branch forDocumentReferenceand fell through to the generic object branch, which recursed into the cyclic_firestoregetter.deserializeDatathat returns a{ __type__: 'documentReference', id, path }marker, mirroring the existingTimestamp/GeoPointhandling.serializeMarkercase so a deserialized reference can be written back unchanged (round-trip viadoc(getFirestore(), marker.path)).FirestoreDocumentReferencemarker interface todefinitions.ts.Test plan
DocumentReferencefield on web — noRangeErroris thrown.{ __type__: 'documentReference', id, path }for the reference field.setDocument/updateDocument/addDocumentstores it as a real Firestore reference (round-trip).Timestamp,GeoPoint, and other existing data types still serialize/deserialize correctly.Close #975