Skip to content

Commit

Permalink
Remove LocalStorage synchronization on storage events in Safari (#8408)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlarocque authored Aug 6, 2024
1 parent b4c5ef3 commit 2ddbd4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-shirts-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/auth': patch
---

Remove localStorage synchronization on storage events in Safari iframes. See [GitHub PR #8408](https://github.com/firebase/firebase-js-sdk/pull/8408).
37 changes: 1 addition & 36 deletions packages/auth/src/platform_browser/persistence/local_storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@

import { Persistence } from '../../model/public_types';

import { getUA } from '@firebase/util';
import {
_isSafari,
_isIOS,
_isIframe,
_isMobileBrowser,
_isIE10
} from '../../core/util/browser';
import { _isMobileBrowser, _isIE10 } from '../../core/util/browser';
import {
PersistenceInternal as InternalPersistence,
PersistenceType,
Expand All @@ -33,11 +26,6 @@ import {
} from '../../core/persistence';
import { BrowserPersistenceClass } from './browser';

function _iframeCannotSyncWebStorage(): boolean {
const ua = getUA();
return _isSafari(ua) || _isIOS(ua);
}

// The polling period in case events are not supported
export const _POLLING_INTERVAL_MS = 1000;

Expand All @@ -64,9 +52,6 @@ class BrowserLocalPersistence
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private pollTimer: any | null = null;

// Safari or iOS browser and embedded in an iframe.
private readonly safariLocalStorageNotSynced =
_iframeCannotSyncWebStorage() && _isIframe();
// Whether to use polling instead of depending on window events
private readonly fallbackToPolling = _isMobileBrowser();
readonly _shouldAllowMigration = true;
Expand Down Expand Up @@ -112,26 +97,6 @@ class BrowserLocalPersistence
this.stopPolling();
}

// Safari embedded iframe. Storage event will trigger with the delta
// changes but no changes will be applied to the iframe localStorage.
if (this.safariLocalStorageNotSynced) {
// Get current iframe page value.
const storedValue = this.storage.getItem(key);
// Value not synchronized, synchronize manually.
if (event.newValue !== storedValue) {
if (event.newValue !== null) {
// Value changed from current value.
this.storage.setItem(key, event.newValue);
} else {
// Current value deleted.
this.storage.removeItem(key);
}
} else if (this.localCache[key] === event.newValue && !poll) {
// Already detected and processed, do not trigger listeners again.
return;
}
}

const triggerListeners = (): void => {
// Keep local map up to date in case storage event is triggered before
// poll.
Expand Down

0 comments on commit 2ddbd4e

Please sign in to comment.