Skip to content

Rename multi-tab setting to synchronizeTabs #1728

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
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 13 additions & 4 deletions packages/firebase/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5942,11 +5942,20 @@ declare namespace firebase.firestore {
* shared execution of queries and latency-compensated local document updates
* across all connected instances.
*
* To enable this mode, `experimentalTabSynchronization:true` needs to be set
* globally in all active tabs. If omitted or set to 'false',
* `enablePersistence()` will fail in all but the first tab.
* To enable this mode, `synchronizeTabs:true` needs to be set globally in all
* active tabs. If omitted or set to 'false', `enablePersistence()` will fail
* in all but the first tab.
*/
synchronizeTabs?: boolean;

/**
* Whether to synchronize the in-memory state of multiple tabs. Setting this
* to 'true' in all open tabs enables shared access to local persistence,
* shared execution of queries and latency-compensated local document updates
* across all connected instances.
*
* NOTE: This mode is not yet recommended for production use.
* @deprecated This setting is deprecated. To enabled synchronization between
* multiple tabs, please use `synchronizeTabs: true` instead.
*/
experimentalTabSynchronization?: boolean;
}
Expand Down
17 changes: 13 additions & 4 deletions packages/firestore-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,20 @@ export interface PersistenceSettings {
* shared execution of queries and latency-compensated local document updates
* across all connected instances.
*
* To enable this mode, `experimentalTabSynchronization:true` needs to be set
* globally in all active tabs. If omitted or set to 'false',
* `enablePersistence()` will fail in all but the first tab.
* To enable this mode, `synchronizeTabs:true` needs to be set globally in all
* active tabs. If omitted or set to 'false', `enablePersistence()` will fail
* in all but the first tab.
*/
synchronizeTabs?: boolean;

/**
* Whether to synchronize the in-memory state of multiple tabs. Setting this
* to 'true' in all open tabs enables shared access to local persistence,
* shared execution of queries and latency-compensated local document updates
* across all connected instances.
*
* NOTE: This mode is not yet recommended for production use.
* @deprecated This setting is deprecated. To enabled synchronization between
* multiple tabs, please use `synchronizeTabs: true` instead.
*/
experimentalTabSynchronization?: boolean;
}
Expand Down
4 changes: 4 additions & 0 deletions packages/firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Unreleased
- [changed] Deprecated the `experimentalTabSynchronization` setting in favor of
`synchronizeTabs`. If you use multi-tab synchronization, it is recommended
that you update your call to `enablePersistence()`. Firestore logs an error
if you continue to use `experimentalTabSynchronization`.
- [feature] Added an `experimentalForceLongPolling` setting that that can be
used to work around proxies that prevent the Firestore client from connecting
to the Firestore backend.
Expand Down
26 changes: 21 additions & 5 deletions packages/firestore/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,14 +398,30 @@ export class Firestore implements firestore.FirebaseFirestore, FirebaseService {
'any other methods on a Firestore object.'
);
}

let synchronizeTabs = false;

if (settings) {
if (settings.experimentalTabSynchronization !== undefined) {
log.error(
'The `experimentalTabSynchronization` setting has been renamed to ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably super nitty but I don't think we usually use backticks within log messages. I'd remove or replace with '

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't like the message without any quoting, but I am fine just using single quotes.

'`synchronizeTabs`. In a future release, the setting will be removed ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra space in setting will

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, I thought I fixed this before sending this out. It's fixed now.

'and it is recommended that you remove it from your ' +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be overly paranoid but I worry "the setting will be removed" and "recommend that you remove it" could potentially be ambiguous and lead people to remove the setting entirely. Perhaps:

In a future release, 'experimentalTabSynchronization' will be removed, so you should update your firestore.enablePersistence() call to use 'synchronizeTabs' now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that works and reduces code duplication :)

'firestore.enablePersistence() call now.'
);
}
synchronizeTabs = objUtils.defaulted(
settings.synchronizeTabs !== undefined
? settings.synchronizeTabs
: settings.experimentalTabSynchronization,
DEFAULT_SYNCHRONIZE_TABS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Way to go naming the default correctly ahead of time!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you assume the API proposal wasn't based on this name? :)

);
}

return this.configureClient(
new IndexedDbPersistenceSettings(
this._config.settings.cacheSizeBytes,
settings !== undefined &&
objUtils.defaulted(
settings.experimentalTabSynchronization,
DEFAULT_SYNCHRONIZE_TABS
)
synchronizeTabs
)
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/core/firestore_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const DOM_EXCEPTION_QUOTA_EXCEEDED = 22;
export class IndexedDbPersistenceSettings {
constructor(
readonly cacheSizeBytes: number,
readonly experimentalTabSynchronization: boolean
readonly synchronizeTabs: boolean
) {}

lruParams(): LruParams {
Expand Down Expand Up @@ -334,7 +334,7 @@ export class FirestoreClient {

return Promise.resolve().then(async () => {
if (
settings.experimentalTabSynchronization &&
settings.synchronizeTabs &&
!WebStorageSharedClientState.isAvailable(this.platform)
) {
throw new FirestoreError(
Expand All @@ -345,7 +345,7 @@ export class FirestoreClient {

let persistence: IndexedDbPersistence;
const lruParams = settings.lruParams();
if (settings.experimentalTabSynchronization) {
if (settings.synchronizeTabs) {
this.sharedClientState = new WebStorageSharedClientState(
this.asyncQueue,
this.platform,
Expand Down
8 changes: 4 additions & 4 deletions packages/firestore/src/local/indexeddb_persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ const PRIMARY_LEASE_LOST_ERROR_MSG =
const PRIMARY_LEASE_EXCLUSIVE_ERROR_MSG =
'Another tab has exclusive access to the persistence layer. ' +
'To allow shared access, make sure to invoke ' +
'`enablePersistence()` with `experimentalTabSynchronization:true` in all tabs.';
'`enablePersistence()` with `synchronizeTabs:true` in all tabs.';
const UNSUPPORTED_PLATFORM_ERROR_MSG =
'This platform is either missing' +
' IndexedDB or is known to have an incomplete implementation. Offline' +
Expand All @@ -130,7 +130,7 @@ export class IndexedDbTransaction extends PersistenceTransaction {
* layer. This allows multiple browser tabs to read and write to IndexedDb and
* to synchronize state even without network connectivity. Shared access is
* currently optional and not enabled unless all clients invoke
* `enablePersistence()` with `{experimentalTabSynchronization:true}`.
* `enablePersistence()` with `{synchronizeTabs:true}`.
*
* In multi-tab mode, if multiple clients are active at the same time, the SDK
* will designate one client as the “primary client”. An effort is made to pick
Expand Down Expand Up @@ -165,8 +165,8 @@ export class IndexedDbTransaction extends PersistenceTransaction {
* LocalStorage which acts as an indicator that another tab should go ahead and
* take the primary lease immediately regardless of the current lease timestamp.
*
* TODO(b/114226234): Remove `experimentalTabSynchronization` section when
* multi-tab is no longer optional.
* TODO(b/114226234): Remove `synchronizeTabs` section when multi-tab is no
* longer optional.
*/
export type MultiClientParams = {
sequenceNumberSyncer: SequenceNumberSyncer;
Expand Down