Skip to content

Commit

Permalink
Allow aggregations to work with multi-tab. (#7212)
Browse files Browse the repository at this point in the history
* Allow aggregations to work with multi-tab.

Fixes #7198.

A proper long-term solution for multi-tab should be implemented.

* Create .changeset/three-months-lie.md

* Improve the change log entry.

* Skip the relevant test.

* Skip the relevant test.
  • Loading branch information
ehsannas authored Apr 12, 2023
1 parent 8c44d58 commit b66908d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/three-months-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/firestore": patch
---

Fix a bug that sometimes prevented aggregations from being run when muli-tab persistence was enabled.
20 changes: 5 additions & 15 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import { newSerializer } from '../platform/serializer';
import { newTextEncoder } from '../platform/text_serializer';
import { Datastore, invokeRunAggregationQueryRpc } from '../remote/datastore';
import {
canUseNetwork,
RemoteStore,
remoteStoreDisableNetwork,
remoteStoreEnableNetwork,
Expand Down Expand Up @@ -536,20 +535,11 @@ export function firestoreClientRunAggregateQuery(
// to the implementation in firestoreClientGetDocumentsViaSnapshotListener
// above
try {
const remoteStore = await getRemoteStore(client);
if (!canUseNetwork(remoteStore)) {
deferred.reject(
new FirestoreError(
Code.UNAVAILABLE,
'Failed to get aggregate result because the client is offline.'
)
);
} else {
const datastore = await getDatastore(client);
deferred.resolve(
invokeRunAggregationQueryRpc(datastore, query, aggregates)
);
}
// TODO(b/277628384): check `canUseNetwork()` and handle multi-tab.
const datastore = await getDatastore(client);
deferred.resolve(
invokeRunAggregationQueryRpc(datastore, query, aggregates)
);
} catch (e) {
deferred.reject(e as Error);
}
Expand Down
8 changes: 6 additions & 2 deletions packages/firestore/test/integration/api/aggregation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ apiDescribe('Count queries', (persistence: boolean) => {
});
});

it('getCountFromServer fails if user is offline', () => {
// TODO(b/277628384): Re-enable this test once b/277628384 is fixed.
// eslint-disable-next-line no-restricted-properties
it.skip('getCountFromServer fails if user is offline', () => {
return withEmptyTestCollection(persistence, async (coll, firestore) => {
await disableNetwork(firestore);
await expect(getCountFromServer(coll)).to.be.eventually.rejectedWith(
Expand Down Expand Up @@ -293,7 +295,9 @@ apiDescribe('Aggregation queries', (persistence: boolean) => {
});
});

it('getAggregateFromServer fails if user is offline', () => {
// TODO(b/277628384): Re-enable this test once b/277628384 is fixed.
// eslint-disable-next-line no-restricted-properties
it.skip('getAggregateFromServer fails if user is offline', () => {
return withEmptyTestCollection(persistence, async (coll, firestore) => {
await disableNetwork(firestore);
await expect(getCountFromServer(coll)).to.be.eventually.rejectedWith(
Expand Down

0 comments on commit b66908d

Please sign in to comment.