Skip to content

Commit

Permalink
Merge 77fb068 into 14b7720
Browse files Browse the repository at this point in the history
  • Loading branch information
hsubox76 authored Jul 19, 2024
2 parents 14b7720 + 77fb068 commit d1995c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/spicy-dragons-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@firebase/app-compat': patch
---

Properly handle the case in app-compat checks where `window` exists but `self` does not. (This occurs in Ionic Stencil's Jest preset.)
10 changes: 8 additions & 2 deletions packages/app-compat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,22 @@ import { firebase as firebaseNamespace } from './firebaseNamespace';
import { logger } from './logger';
import { registerCoreComponents } from './registerCoreComponents';

declare global {
interface Window {
firebase: FirebaseNamespace;
}
}

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

// eslint-disable-next-line
const sdkVersion = ((self as any).firebase as FirebaseNamespace).SDK_VERSION;
const sdkVersion = (window.firebase as FirebaseNamespace).SDK_VERSION;
if (sdkVersion && sdkVersion.indexOf('LITE') >= 0) {
logger.warn(`
Warning: You are trying to load Firebase while using Firebase Performance standalone script.
Expand Down
3 changes: 3 additions & 0 deletions packages/util/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export function isNode(): boolean {

/**
* Detect Browser Environment
* Note: This will return true for certain test frameworks that are incompletely
* mimicking a browser, and should not lead to assuming all browser APIs are
* available.
*/
export function isBrowser(): boolean {
return typeof window !== 'undefined' || isWebWorker();
Expand Down

0 comments on commit d1995c8

Please sign in to comment.