diff --git a/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart b/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart index 4c2df96bb3fc..5c62d73b5db8 100644 --- a/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart +++ b/packages/cloud_firestore/cloud_firestore/example/integration_test/query_e2e.dart @@ -1023,6 +1023,33 @@ void runQueryTests() { expect(snapshot.docs[1].id, equals('doc4')); }); + test( + 'startAfterDocument() preserves Timestamp cursor precision', + () async { + CollectionReference> collection = + await initializeTest('startAfter-document-timestamp-precision'); + await collection.doc('doc1').set({ + 'createdAt': Timestamp(1, 123456789), + }); + + Query> baseQuery = + collection.orderBy('createdAt'); + QuerySnapshot> firstPage = + await baseQuery.limit(50).get(); + + expect(firstPage.docs.length, equals(1)); + expect(firstPage.docs.first.id, equals('doc1')); + + QuerySnapshot> nextPage = await baseQuery + .startAfterDocument(firstPage.docs.last) + .limit(50) + .get(); + + expect(nextPage.docs, isEmpty); + }, + skip: !kIsWeb, + ); + testWidgets( 'throws exception without orderBy() on field used for inequality query', (_) async { diff --git a/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/encode_utility.dart b/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/encode_utility.dart index ca5f5bf5ea4b..acc3f880b6e4 100644 --- a/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/encode_utility.dart +++ b/packages/cloud_firestore/cloud_firestore_web/lib/src/utils/encode_utility.dart @@ -120,7 +120,10 @@ class EncodeUtility { } else if (value == FieldPath.documentId) { return firestore_interop.documentId(); } else if (value is Timestamp) { - return value.toDate(); + return firestore_interop.TimestampJsImpl( + value.seconds.toJS, + value.nanoseconds.toJS, + ); } else if (value is GeoPoint) { return firestore_interop.GeoPointJsImpl( value.latitude.toJS, value.longitude.toJS);