Skip to content

Convert DocumentReference values in Firestore document data - #110

Open
abdul10ahad wants to merge 1 commit into
skiptools:mainfrom
abdul10ahad:fix-document-reference-bridging
Open

abdul10ahad wants to merge 1 commit into
skiptools:mainfrom
abdul10ahad:fix-document-reference-bridging

Conversation

@abdul10ahad

@abdul10ahad abdul10ahad commented Nov 22, 2026 •

Copy link
Copy Markdown

Fixes #109.

DocumentSnapshot.data() crashes a native (Fuse) Android app when the document has a field of type reference: firestoreDeepSwift(value:) returns a com.google.firebase.firestore.DocumentReference as a raw Kotlin object, and AnyBridging.fromJavaObject has no Swift type for it when the dictionary crosses the bridge.

     if let gp = value as? com.google.firebase.firestore.GeoPoint {
         return GeoPoint(latitude: gp.latitude, longitude: gp.longitude)
     }
+    if let ref = value as? com.google.firebase.firestore.DocumentReference {
+        return DocumentReference(ref: ref)
+    }

The reference becomes the module's own DocumentReference, the same way Timestamp and GeoPoint are handled. Maps and collections recurse through this function, so nested references are covered.

Evidence

Standalone Skip Fuse app reading a document with a top-level and a nested reference from a local Firestore emulator (details in #109), arm64 emulator, API 37. This change was applied on top of 0.21.1 for the test.

  • Before (0.21.1):
    repro: with-reference: fetched, calling data()
    Fatal signal 5 (SIGTRAP), code 1 (TRAP_BRKPT)
    #01 libSkipBridge.so             AnyBridging.fromJavaObject(_:options:fallback:)
    #09 libSkipFirebaseFirestore.so  DocumentSnapshot.data()
    
  • After:
    repro: with-reference: ["amount", "defaults", "name", "price", "tax_group"]
    repro: tax_group: DocumentReference tax-groups/g1
    repro: defaults.DRINK (nested in a map): DocumentReference tax-groups/g2
    

One run per side. Not tested: references inside arrays, a transpiled (Lite) app, and this repository's test suite. No test added. The repository has Firestore tests, but I have not worked out whether they can exercise the native bridge path where this crash happens; glad to add one if you can point me at the right place.

DocumentSnapshot.data() left a com.google.firebase.firestore.DocumentReference as a raw Kotlin object, which SkipBridge cannot convert in a native (Fuse) app, so reading any document with a reference field crashed on Android. Convert it to the module's DocumentReference, like Timestamp and GeoPoint. Fixes skiptools#109.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Firestore: DocumentSnapshot.data() crashes on Android (Fuse) when a field is a DocumentReference

1 participant