Skip to content

Commit aaf3fa3

Browse files
authored
Fix an issue where localCache is not copied as part of Settings (#7385)
* add test * Fix a bug where localCache is not copied as part of Settings * Remove debug logging * Create eighty-tomatoes-trade.md
1 parent 534047b commit aaf3fa3

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

.changeset/eighty-tomatoes-trade.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@firebase/firestore": patch
3+
"firebase": patch
4+
---
5+
6+
Fix an issue where localCache is not copied as part of Settings.

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
@@ -437,7 +437,7 @@ If the final path has an odd number of segments and does not point to a document
437437

438438
> Warning: This API is now obsolete.
439439
>
440-
> 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.
440+
> 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.
441441
>
442442
443443
Attempts to enable persistent storage, if possible.
@@ -475,7 +475,7 @@ A `Promise` that represents successfully enabling persistent storage.
475475

476476
> Warning: This API is now obsolete.
477477
>
478-
> 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.
478+
> 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.
479479
>
480480
481481
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/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;

0 commit comments

Comments
 (0)