Skip to content

Commit 59c29e9

Browse files
committed
Merge branch 'main' of github.com:firebase/firebase-js-sdk into markduckworth/vector-type
2 parents 9dafcda + 1601572 commit 59c29e9

File tree

5 files changed

+33
-52
lines changed

5 files changed

+33
-52
lines changed

.changeset/mighty-shirts-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/auth': patch
3+
---
4+
5+
Remove localStorage synchronization on storage events in Safari iframes. See [GitHub PR #8408](https://github.com/firebase/firebase-js-sdk/pull/8408).

.changeset/slow-emus-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/app-compat': patch
3+
---
4+
5+
Updated how app-compat checks the global scope.

.github/workflows/check-changeset.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ jobs:
6868
### Changeset File Check :warning:
6969
${{steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
7070
- name: Update comment (missing packages)
71-
if: ${{steps.fc.outputs.comment-id}}
71+
if: ${{steps.fc.outputs.comment-id && steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
7272
uses: peter-evans/create-or-update-comment@v4
7373
with:
74-
comment-id: ${{steps.fc.outputs.comment-id}} && steps.check-changeset.outputs.CHANGESET_ERROR_MESSAGE}}
74+
comment-id: ${{steps.fc.outputs.comment-id}}
7575
edit-mode: replace
7676
body: |
7777
### Changeset File Check :warning:

packages/app-compat/src/index.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { FirebaseNamespace } from './public-types';
19-
import { isBrowser } from '@firebase/util';
19+
import { getGlobal } from '@firebase/util';
2020
import { firebase as firebaseNamespace } from './firebaseNamespace';
2121
import { logger } from './logger';
2222
import { registerCoreComponents } from './registerCoreComponents';
@@ -27,22 +27,28 @@ declare global {
2727
}
2828
}
2929

30-
// Firebase Lite detection
31-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
32-
if (isBrowser() && window.firebase !== undefined) {
33-
logger.warn(`
34-
Warning: Firebase is already defined in the global scope. Please make sure
35-
Firebase library is only loaded once.
36-
`);
37-
38-
// eslint-disable-next-line
39-
const sdkVersion = (window.firebase as FirebaseNamespace).SDK_VERSION;
40-
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
30+
try {
31+
const globals = getGlobal();
32+
// Firebase Lite detection
33+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34+
if ((globals as any).firebase !== undefined) {
4135
logger.warn(`
42-
Warning: You are trying to load Firebase while using Firebase Performance standalone script.
43-
You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.
36+
Warning: Firebase is already defined in the global scope. Please make sure
37+
Firebase library is only loaded once.
4438
`);
39+
40+
// eslint-disable-next-line
41+
const sdkVersion = ((globals as any).firebase as FirebaseNamespace)
42+
.SDK_VERSION;
43+
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
44+
logger.warn(`
45+
Warning: You are trying to load Firebase while using Firebase Performance standalone script.
46+
You should load Firebase Performance with this instance of Firebase to avoid loading duplicate code.
47+
`);
48+
}
4549
}
50+
} catch {
51+
// ignore errors thrown by getGlobal
4652
}
4753

4854
const firebase = firebaseNamespace;

packages/auth/src/platform_browser/persistence/local_storage.ts

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@
1717

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

20-
import { getUA } from '@firebase/util';
21-
import {
22-
_isSafari,
23-
_isIOS,
24-
_isIframe,
25-
_isMobileBrowser,
26-
_isIE10
27-
} from '../../core/util/browser';
20+
import { _isMobileBrowser, _isIE10 } from '../../core/util/browser';
2821
import {
2922
PersistenceInternal as InternalPersistence,
3023
PersistenceType,
@@ -33,11 +26,6 @@ import {
3326
} from '../../core/persistence';
3427
import { BrowserPersistenceClass } from './browser';
3528

36-
function _iframeCannotSyncWebStorage(): boolean {
37-
const ua = getUA();
38-
return _isSafari(ua) || _isIOS(ua);
39-
}
40-
4129
// The polling period in case events are not supported
4230
export const _POLLING_INTERVAL_MS = 1000;
4331

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

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

115-
// Safari embedded iframe. Storage event will trigger with the delta
116-
// changes but no changes will be applied to the iframe localStorage.
117-
if (this.safariLocalStorageNotSynced) {
118-
// Get current iframe page value.
119-
const storedValue = this.storage.getItem(key);
120-
// Value not synchronized, synchronize manually.
121-
if (event.newValue !== storedValue) {
122-
if (event.newValue !== null) {
123-
// Value changed from current value.
124-
this.storage.setItem(key, event.newValue);
125-
} else {
126-
// Current value deleted.
127-
this.storage.removeItem(key);
128-
}
129-
} else if (this.localCache[key] === event.newValue && !poll) {
130-
// Already detected and processed, do not trigger listeners again.
131-
return;
132-
}
133-
}
134-
135100
const triggerListeners = (): void => {
136101
// Keep local map up to date in case storage event is triggered before
137102
// poll.

0 commit comments

Comments
 (0)