Skip to content

Commit 7522b43

Browse files
committed
Merge remote-tracking branch 'remotes/origin/dconeybe/LongPollingLogicTweak' into AutoDetectLongPollingEnabledByDefault
2 parents e0e0741 + 17519c3 commit 7522b43

File tree

2 files changed

+52
-9
lines changed

2 files changed

+52
-9
lines changed

packages/firestore/src/lite-api/settings.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import { validateIsNotUsedTogether } from '../util/input_validation';
2929
export const DEFAULT_HOST = 'firestore.googleapis.com';
3030
export const DEFAULT_SSL = true;
3131

32+
const DEFAULT_AUTO_DETECT_LONG_POLLING = true;
33+
3234
/**
3335
* Specifies custom configurations for your Cloud Firestore instance.
3436
* You must set these before invoking any other methods.
@@ -130,17 +132,18 @@ export class FirestoreSettingsImpl {
130132
settings.experimentalAutoDetectLongPolling
131133
);
132134

133-
if (settings.experimentalForceLongPolling) {
134-
this.experimentalForceLongPolling = true;
135+
this.experimentalForceLongPolling = !!settings.experimentalForceLongPolling;
136+
137+
if (this.experimentalForceLongPolling) {
135138
this.experimentalAutoDetectLongPolling = false;
139+
} else if (settings.experimentalAutoDetectLongPolling === undefined) {
140+
this.experimentalAutoDetectLongPolling = DEFAULT_AUTO_DETECT_LONG_POLLING;
136141
} else {
137-
this.experimentalForceLongPolling = false;
138-
if (settings.experimentalAutoDetectLongPolling === undefined) {
139-
this.experimentalAutoDetectLongPolling = true;
140-
} else {
141-
this.experimentalAutoDetectLongPolling =
142-
settings.experimentalAutoDetectLongPolling;
143-
}
142+
// For backwards compatibility, coerce the value to boolean even though
143+
// the TypeScript compiler has narrowed the type to boolean already.
144+
// noinspection PointlessBooleanExpressionJS
145+
this.experimentalAutoDetectLongPolling =
146+
!!settings.experimentalAutoDetectLongPolling;
144147
}
145148

146149
this.useFetchStreams = !!settings.useFetchStreams;

packages/firestore/test/unit/api/database.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,46 @@ describe('Settings', () => {
359359
expect(db._getSettings().experimentalForceLongPolling).to.be.false;
360360
});
361361

362+
it('long polling autoDetect=[something truthy] should be coerced to true', () => {
363+
// Use a new instance of Firestore in order to configure settings.
364+
const db = newTestFirestore();
365+
db._setSettings({
366+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
367+
experimentalAutoDetectLongPolling: 1 as any
368+
});
369+
expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.true;
370+
});
371+
372+
it('long polling autoDetect=[something falsy] should be coerced to false', () => {
373+
// Use a new instance of Firestore in order to configure settings.
374+
const db = newTestFirestore();
375+
db._setSettings({
376+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
377+
experimentalAutoDetectLongPolling: 0 as any
378+
});
379+
expect(db._getSettings().experimentalAutoDetectLongPolling).to.be.false;
380+
});
381+
382+
it('long polling force=[something truthy] should be coerced to true', () => {
383+
// Use a new instance of Firestore in order to configure settings.
384+
const db = newTestFirestore();
385+
db._setSettings({
386+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
387+
experimentalForceLongPolling: 'I am truthy' as any
388+
});
389+
expect(db._getSettings().experimentalForceLongPolling).to.be.true;
390+
});
391+
392+
it('long polling force=[something falsy] should be coerced to false', () => {
393+
// Use a new instance of Firestore in order to configure settings.
394+
const db = newTestFirestore();
395+
db._setSettings({
396+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
397+
experimentalForceLongPolling: NaN as any
398+
});
399+
expect(db._getSettings().experimentalForceLongPolling).to.be.false;
400+
});
401+
362402
it('gets settings from useEmulator', () => {
363403
// Use a new instance of Firestore in order to configure settings.
364404
const db = newTestFirestore();

0 commit comments

Comments
 (0)