Skip to content

Allow aggregations to work with multi-tab. #7212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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