Skip to content

Commit ed1c993

Browse files
authored
FirebaseServerAppImpl: guard use of FinalizationRegistry based on its availability. (#8335)
There was code that would errantly attempt to allocate a FinalizationRegstiry in FirebaseServerAppImpl regardless of the existence of releaseOnDeref field, and this caused issues in some edge environments. This change fixes that issue.
1 parent 192561b commit ed1c993

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.changeset/clever-dryers-double.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@firebase/app': patch
3+
'firebase': patch
4+
---
5+
6+
Guard the use of `FinalizationRegistry` in `FirebaseServerApp` initialization based on the availability of `FinalizationRegistry` in the runtime.

packages/app/src/firebaseServerApp.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class FirebaseServerAppImpl
3232
implements FirebaseServerApp
3333
{
3434
private readonly _serverConfig: FirebaseServerAppSettings;
35-
private _finalizationRegistry: FinalizationRegistry<object>;
35+
private _finalizationRegistry: FinalizationRegistry<object> | null;
3636
private _refCount: number;
3737

3838
constructor(
@@ -67,9 +67,12 @@ export class FirebaseServerAppImpl
6767
...serverConfig
6868
};
6969

70-
this._finalizationRegistry = new FinalizationRegistry(() => {
71-
this.automaticCleanup();
72-
});
70+
this._finalizationRegistry = null;
71+
if (typeof FinalizationRegistry !== 'undefined') {
72+
this._finalizationRegistry = new FinalizationRegistry(() => {
73+
this.automaticCleanup();
74+
});
75+
}
7376

7477
this._refCount = 0;
7578
this.incRefCount(this._serverConfig.releaseOnDeref);
@@ -97,7 +100,7 @@ export class FirebaseServerAppImpl
97100
return;
98101
}
99102
this._refCount++;
100-
if (obj !== undefined) {
103+
if (obj !== undefined && this._finalizationRegistry !== null) {
101104
this._finalizationRegistry.register(obj, this);
102105
}
103106
}

0 commit comments

Comments
 (0)