Skip to content

Commit

Permalink
fix(firestore, web): fix an issue where hot restart would throw an er…
Browse files Browse the repository at this point in the history
…ror in console (#12382)
  • Loading branch information
Lyokone committed Feb 23, 2024
1 parent fa412b4 commit a5dc05d
Showing 1 changed file with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import 'dart:async';
import 'dart:js_interop';
import 'dart:typed_data';

import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart'
as platform_interface;
Expand All @@ -16,6 +15,7 @@ import 'package:cloud_firestore_web/src/utils/encode_utility.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_core_web/firebase_core_web_interop.dart'
hide jsify, dartify;
import 'package:flutter/foundation.dart';

import 'firestore_interop.dart' as firestore_interop;
import 'utils/utils.dart';
Expand All @@ -31,8 +31,17 @@ Firestore getFirestoreInstance([
String database = databaseURL ?? '(default)';

if (app != null && settings != null) {
return Firestore.getInstance(firestore_interop.initializeFirestore(
app.jsObject, settings, database.toJS));
try {
return Firestore.getInstance(firestore_interop.initializeFirestore(
app.jsObject, settings, database.toJS));
} catch (e) {
if (kDebugMode) {
// Fallback to initialize without settings, happens during hot restart
return Firestore.getInstance(
firestore_interop.getFirestore(app.jsObject, database.toJS));
}
rethrow;
}
}

return Firestore.getInstance(app != null
Expand Down

0 comments on commit a5dc05d

Please sign in to comment.