Skip to content

Commit e89cfd2

Browse files
davidmiglozclaude
andcommitted
fix(firebase_core, web): return empty list from apps getter in WASM mode
Fixes #17918 The `apps` getter now checks if the Firebase core module is loaded before accessing `firebase.apps`. This avoids triggering a JavaScript exception when Firebase is not initialized, which is more efficient than relying on exception handling. This change ensures `Firebase.apps` returns an empty list in both JS and WASM web builds when called before `Firebase.initializeApp()`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 48e6e17 commit e89cfd2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

packages/firebase_core/firebase_core_web/lib/src/firebase_core_web.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ class FirebaseCoreWeb extends FirebasePlatform {
227227
/// Returns all created [FirebaseAppPlatform] instances.
228228
@override
229229
List<FirebaseAppPlatform> get apps {
230+
// Check if Firebase core module is loaded before accessing firebase.apps
231+
if (globalContext.getProperty('firebase_core'.toJS) == null) {
232+
return [];
233+
}
234+
230235
try {
231236
return firebase.apps.map(_createFromJsApp).toList(growable: false);
232237
} catch (exception, stackTrace) {

packages/firebase_core/firebase_core_web/test/firebase_core_web_exceptions_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,16 @@ void main() {
3939
});
4040
});
4141
});
42+
43+
group('apps getter', () {
44+
setUp(() async {
45+
FirebasePlatform.instance = FirebaseCoreWeb();
46+
});
47+
48+
test(
49+
'should return empty list when Firebase is not initialized',
50+
() {
51+
expect(FirebasePlatform.instance.apps, isEmpty);
52+
});
53+
});
4254
}

0 commit comments

Comments
 (0)