Skip to content

Fix an issue where localCache is not copied as part of Settings #7385

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 4 commits into from
Jun 26, 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
6 changes: 6 additions & 0 deletions .changeset/eighty-tomatoes-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@firebase/firestore": patch
"firebase": patch
---

Fix an issue where localCache is not copied as part of Settings.
4 changes: 2 additions & 2 deletions docs-devsite/firestore_.firestoresettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export declare interface FirestoreSettings
| [experimentalLongPollingOptions](./firestore_.firestoresettings.md#firestoresettingsexperimentallongpollingoptions) | [ExperimentalLongPollingOptions](./firestore_.experimentallongpollingoptions.md#experimentallongpollingoptions_interface) | Options that configure the SDK’s 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. |
| [host](./firestore_.firestoresettings.md#firestoresettingshost) | string | The hostname to connect to. |
| [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>. |
| [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. |
| [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. |
| [ssl](./firestore_.firestoresettings.md#firestoresettingsssl) | boolean | Whether to use SSL when connecting. |

## FirestoreSettings.cacheSizeBytes
Expand Down Expand Up @@ -107,7 +107,7 @@ ignoreUndefinedProperties?: boolean;

## FirestoreSettings.localCache

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

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

Expand Down
4 changes: 2 additions & 2 deletions docs-devsite/firestore_.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ If the final path has an odd number of segments and does not point to a document

> Warning: This API is now obsolete.
>
> 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.
> 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.
>

Attempts to enable persistent storage, if possible.
Expand Down Expand Up @@ -475,7 +475,7 @@ A `Promise` that represents successfully enabling persistent storage.

> Warning: This API is now obsolete.
>
> 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.
> 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.
>

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.
Expand Down
18 changes: 9 additions & 9 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,13 @@ export function configureFirestore(firestore: Firestore): void {
databaseInfo
);
if (
settings.cache?._offlineComponentProvider &&
settings.cache?._onlineComponentProvider
settings.localCache?._offlineComponentProvider &&
settings.localCache?._onlineComponentProvider
) {
firestore._firestoreClient._uninitializedComponentsProvider = {
_offlineKind: settings.cache.kind,
_offline: settings.cache._offlineComponentProvider,
_online: settings.cache._onlineComponentProvider
_offlineKind: settings.localCache.kind,
_offline: settings.localCache._offlineComponentProvider,
_online: settings.localCache._onlineComponentProvider
};
}
}
Expand Down Expand Up @@ -327,8 +327,8 @@ export function configureFirestore(firestore: Firestore): void {
* persistence.
* @returns A `Promise` that represents successfully enabling persistent storage.
* @deprecated 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`
* `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.
*/
export function enableIndexedDbPersistence(
Expand Down Expand Up @@ -387,8 +387,8 @@ export function enableIndexedDbPersistence(
* @returns A `Promise` that represents successfully enabling persistent
* storage.
* @deprecated 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`
* `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.
*/
export function enableMultiTabIndexedDbPersistence(
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface FirestoreSettings extends LiteSettings {

/**
* Specifies the cache used by the SDK. Available options are `MemoryLocalCache`
* and `IndexedDbLocalCache`, each with different configuration options.
* and `PersistentLocalCache`, each with different configuration options.
*
* When unspecified, `MemoryLocalCache` will be used by default.
*
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/lite-api/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class FirestoreSettingsImpl {
readonly ignoreUndefinedProperties: boolean;

readonly useFetchStreams: boolean;
readonly cache?: FirestoreLocalCache;
readonly localCache?: FirestoreLocalCache;

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

this.credentials = settings.credentials;
this.ignoreUndefinedProperties = !!settings.ignoreUndefinedProperties;
this.cache = settings.localCache;
this.localCache = settings.localCache;

if (settings.cacheSizeBytes === undefined) {
this.cacheSizeBytes = LRU_DEFAULT_CACHE_SIZE_BYTES;
Expand Down