Skip to content

Commit 39fef1f

Browse files
committed
Handle JSDOM case in app-compat checks
1 parent 14b7720 commit 39fef1f

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.changeset/spicy-dragons-pay.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+
Handle JSDOM case in app-compat checks.

packages/app-compat/src/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@
1616
*/
1717

1818
import { FirebaseNamespace } from './public-types';
19-
import { isBrowser } from '@firebase/util';
19+
import { isBrowser, getGlobal } from '@firebase/util';
2020
import { firebase as firebaseNamespace } from './firebaseNamespace';
2121
import { logger } from './logger';
2222
import { registerCoreComponents } from './registerCoreComponents';
2323

2424
// Firebase Lite detection
2525
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26-
if (isBrowser() && (self as any).firebase !== undefined) {
26+
if (isBrowser() && (getGlobal() as any).firebase !== undefined) {
2727
logger.warn(`
2828
Warning: Firebase is already defined in the global scope. Please make sure
2929
Firebase library is only loaded once.
3030
`);
3131

3232
// eslint-disable-next-line
33-
const sdkVersion = ((self as any).firebase as FirebaseNamespace).SDK_VERSION;
33+
const sdkVersion = ((getGlobal() as any).firebase as FirebaseNamespace)
34+
.SDK_VERSION;
3435
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
3536
logger.warn(`
3637
Warning: You are trying to load Firebase while using Firebase Performance standalone script.

packages/util/src/environment.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ export function isNode(): boolean {
8080

8181
/**
8282
* Detect Browser Environment
83+
* Note: This will return true for JSDOM (e.g. Jest) as it is mimicking
84+
* a browser, and should not lead to assuming all browser APIs are
85+
* available.
8386
*/
8487
export function isBrowser(): boolean {
8588
return typeof window !== 'undefined' || isWebWorker();

0 commit comments

Comments
 (0)