Skip to content

Commit 8ee1650

Browse files
committed
Fix a bug where localCache is not copied as part of Settings
1 parent 566a688 commit 8ee1650

File tree

7 files changed

+26
-40
lines changed

7 files changed

+26
-40
lines changed

docs-devsite/firestore_.firestoresettings.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export declare interface FirestoreSettings
2828
| [experimentalLongPollingOptions](./firestore_.firestoresettings.md#firestoresettingsexperimentallongpollingoptions) | [ExperimentalLongPollingOptions](./firestore_.experimentallongpollingoptions.md#experimentallongpollingoptions_interface) | Options that configure the SDKs underlying network transport (WebChannel) when long-polling is used.<!-- -->These options are only used if <code>experimentalForceLongPolling</code> is true or if <code>experimentalAutoDetectLongPolling</code> is true and the auto-detection determined that long-polling was needed. Otherwise, these options have no effect. |
2929
| [host](./firestore_.firestoresettings.md#firestoresettingshost) | string | The hostname to connect to. |
3030
| [ignoreUndefinedProperties](./firestore_.firestoresettings.md#firestoresettingsignoreundefinedproperties) | boolean | Whether to skip nested properties that are set to <code>undefined</code> during object serialization. If set to <code>true</code>, these properties are skipped and not written to Firestore. If set to <code>false</code> or omitted, the SDK throws an exception when it encounters properties of type <code>undefined</code>. |
31-
| [localCache](./firestore_.firestoresettings.md#firestoresettingslocalcache) | [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Specifies the cache used by the SDK. Available options are <code>MemoryLocalCache</code> and <code>IndexedDbLocalCache</code>, each with different configuration options.<!-- -->When unspecified, <code>MemoryLocalCache</code> will be used by default.<!-- -->NOTE: setting this field and <code>cacheSizeBytes</code> at the same time will throw exception during SDK initialization. Instead, using the configuration in the <code>FirestoreLocalCache</code> object to specify the cache size. |
31+
| [localCache](./firestore_.firestoresettings.md#firestoresettingslocalcache) | [FirestoreLocalCache](./firestore_.md#firestorelocalcache) | Specifies the cache used by the SDK. Available options are <code>MemoryLocalCache</code> and <code>PersistentLocalCache</code>, each with different configuration options.<!-- -->When unspecified, <code>MemoryLocalCache</code> will be used by default.<!-- -->NOTE: setting this field and <code>cacheSizeBytes</code> at the same time will throw exception during SDK initialization. Instead, using the configuration in the <code>FirestoreLocalCache</code> object to specify the cache size. |
3232
| [ssl](./firestore_.firestoresettings.md#firestoresettingsssl) | boolean | Whether to use SSL when connecting. |
3333

3434
## FirestoreSettings.cacheSizeBytes
@@ -107,7 +107,7 @@ ignoreUndefinedProperties?: boolean;
107107

108108
## FirestoreSettings.localCache
109109

110-
Specifies the cache used by the SDK. Available options are `MemoryLocalCache` and `IndexedDbLocalCache`<!-- -->, each with different configuration options.
110+
Specifies the cache used by the SDK. Available options are `MemoryLocalCache` and `PersistentLocalCache`<!-- -->, each with different configuration options.
111111

112112
When unspecified, `MemoryLocalCache` will be used by default.
113113

docs-devsite/firestore_.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ If the final path has an odd number of segments and does not point to a document
408408

409409
> Warning: This API is now obsolete.
410410
>
411-
> This function will be removed in a future major release. Instead, set `FirestoreSettings.cache` to an instance of `IndexedDbLocalCache` to turn on IndexedDb cache. Calling this function when `FirestoreSettings.cache` is already specified will throw an exception.
411+
> This function will be removed in a future major release. Instead, set `FirestoreSettings.localCache` to an instance of `PersistentLocalCache` to turn on IndexedDb cache. Calling this function when `FirestoreSettings.localCache` is already specified will throw an exception.
412412
>
413413
414414
Attempts to enable persistent storage, if possible.
@@ -446,7 +446,7 @@ A `Promise` that represents successfully enabling persistent storage.
446446

447447
> Warning: This API is now obsolete.
448448
>
449-
> This function will be removed in a future major release. Instead, set `FirestoreSettings.cache` to an instance of `IndexedDbLocalCache` to turn on indexeddb cache. Calling this function when `FirestoreSettings.cache` is already specified will throw an exception.
449+
> This function will be removed in a future major release. Instead, set `FirestoreSettings.localCache` to an instance of `PersistentLocalCache` to turn on indexeddb cache. Calling this function when `FirestoreSettings.localCache` is already specified will throw an exception.
450450
>
451451
452452
Attempts to enable multi-tab persistent storage, if possible. If enabled across all tabs, all operations share access to local persistence, including shared execution of queries and latency-compensated local document updates across all connected instances.

packages/firestore/src/api/database.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ export function configureFirestore(firestore: Firestore): void {
291291
databaseInfo
292292
);
293293
if (
294-
settings.cache?._offlineComponentProvider &&
295-
settings.cache?._onlineComponentProvider
294+
settings.localCache?._offlineComponentProvider &&
295+
settings.localCache?._onlineComponentProvider
296296
) {
297297
firestore._firestoreClient._uninitializedComponentsProvider = {
298-
_offlineKind: settings.cache.kind,
299-
_offline: settings.cache._offlineComponentProvider,
300-
_online: settings.cache._onlineComponentProvider
298+
_offlineKind: settings.localCache.kind,
299+
_offline: settings.localCache._offlineComponentProvider,
300+
_online: settings.localCache._onlineComponentProvider
301301
};
302302
}
303303
}
@@ -327,8 +327,8 @@ export function configureFirestore(firestore: Firestore): void {
327327
* persistence.
328328
* @returns A `Promise` that represents successfully enabling persistent storage.
329329
* @deprecated This function will be removed in a future major release. Instead, set
330-
* `FirestoreSettings.cache` to an instance of `IndexedDbLocalCache` to
331-
* turn on IndexedDb cache. Calling this function when `FirestoreSettings.cache`
330+
* `FirestoreSettings.localCache` to an instance of `PersistentLocalCache` to
331+
* turn on IndexedDb cache. Calling this function when `FirestoreSettings.localCache`
332332
* is already specified will throw an exception.
333333
*/
334334
export function enableIndexedDbPersistence(
@@ -387,8 +387,8 @@ export function enableIndexedDbPersistence(
387387
* @returns A `Promise` that represents successfully enabling persistent
388388
* storage.
389389
* @deprecated This function will be removed in a future major release. Instead, set
390-
* `FirestoreSettings.cache` to an instance of `IndexedDbLocalCache` to
391-
* turn on indexeddb cache. Calling this function when `FirestoreSettings.cache`
390+
* `FirestoreSettings.localCache` to an instance of `PersistentLocalCache` to
391+
* turn on indexeddb cache. Calling this function when `FirestoreSettings.localCache`
392392
* is already specified will throw an exception.
393393
*/
394394
export function enableMultiTabIndexedDbPersistence(

packages/firestore/src/api/settings.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export interface FirestoreSettings extends LiteSettings {
6060

6161
/**
6262
* Specifies the cache used by the SDK. Available options are `MemoryLocalCache`
63-
* and `IndexedDbLocalCache`, each with different configuration options.
63+
* and `PersistentLocalCache`, each with different configuration options.
6464
*
6565
* When unspecified, `MemoryLocalCache` will be used by default.
6666
*

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

+9-2
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export function connectFirestoreEmulator(
302302
firestore = cast(firestore, Firestore);
303303
const settings = firestore._getSettings();
304304

305-
logWarn(`before connect emulator, settings is {JSON.stringify(settings)}`);
305+
logWarn(`before connect emulator, settings is ${JSON.stringify(settings)}`);
306306
if (settings.host !== DEFAULT_HOST && settings.host !== host) {
307307
logWarn(
308308
'Host has been set in both settings() and useEmulator(), emulator host ' +
@@ -315,8 +315,15 @@ export function connectFirestoreEmulator(
315315
host: `${host}:${port}`,
316316
ssl: false
317317
};
318-
logWarn(`after connect emulator, settings is ${JSON.stringify(newSettings)}`);
318+
logWarn(`before set settings ${JSON.stringify(newSettings, undefined, 2)}`);
319319
firestore._setSettings(newSettings);
320+
logWarn(
321+
`after set settings, _getSettings is ${JSON.stringify(
322+
firestore._getSettings(),
323+
undefined,
324+
2
325+
)}`
326+
);
320327

321328
if (options.mockUserToken) {
322329
let token: string;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class FirestoreSettingsImpl {
104104
readonly ignoreUndefinedProperties: boolean;
105105

106106
readonly useFetchStreams: boolean;
107-
readonly cache?: FirestoreLocalCache;
107+
readonly localCache?: FirestoreLocalCache;
108108

109109
// Can be a google-auth-library or gapi client.
110110
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -127,7 +127,7 @@ export class FirestoreSettingsImpl {
127127

128128
this.credentials = settings.credentials;
129129
this.ignoreUndefinedProperties = !!settings.ignoreUndefinedProperties;
130-
this.cache = settings.localCache;
130+
this.localCache = settings.localCache;
131131

132132
if (settings.cacheSizeBytes === undefined) {
133133
this.cacheSizeBytes = LRU_DEFAULT_CACHE_SIZE_BYTES;

packages/firestore/test/integration/api/provider.test.ts

+1-22
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ import {
2929
enableIndexedDbPersistence,
3030
setDoc,
3131
memoryLocalCache,
32-
getDocFromCache,
33-
persistentLocalCache,
34-
connectFirestoreEmulator
32+
getDocFromCache
3533
} from '../util/firebase_export';
3634
import { DEFAULT_SETTINGS } from '../util/settings';
3735

@@ -143,25 +141,6 @@ describe('Firestore Provider', () => {
143141
});
144142
});
145143

146-
it.only('connectFirestoreEmulator() keeps other settings', async () => {
147-
const app = initializeApp(
148-
{ apiKey: 'fake-api-key', projectId: 'test-project' },
149-
'test-use-enablePersistence'
150-
);
151-
const db = initializeFirestore(app, {
152-
...DEFAULT_SETTINGS,
153-
localCache: persistentLocalCache()
154-
});
155-
connectFirestoreEmulator(db, "localhost", 8080);
156-
157-
// SDK still functions.
158-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
159-
setDoc(doc(db, 'coll/doc'), { field: 'foo' });
160-
expect((await getDocFromCache(doc(db, 'coll/doc'))).data()).to.deep.equal({
161-
field: 'foo'
162-
});
163-
});
164-
165144
it('cannot mix enableIndexedDbPersistence() and settings.cache', async () => {
166145
const app = initializeApp(
167146
{ apiKey: 'fake-api-key', projectId: 'test-project' },

0 commit comments

Comments
 (0)