Skip to content

Commit 4ba0ff9

Browse files
fix(cloud_firestore, web): stop FirebaseError appearing in console on hot restart & hot refresh (#9321)
1 parent 1aa1c16 commit 4ba0ff9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/cloud_firestore/cloud_firestore/lib/src/firestore.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,15 @@ class FirebaseFirestore extends FirebasePluginPlatform {
108108
void useFirestoreEmulator(String host, int port, {bool sslEnabled = false}) {
109109
if (kIsWeb) {
110110
// use useEmulator() API for web as settings are set immediately unlike native platforms
111-
_delegate.useEmulator(host, port);
111+
try {
112+
_delegate.useEmulator(host, port);
113+
} catch (e) {
114+
final String code = (e as dynamic).code;
115+
// this catches FirebaseError from web that occurs after hot reloading & hot restarting
116+
if (code != 'failed-precondition') {
117+
rethrow;
118+
}
119+
}
112120
} else {
113121
String mappedHost = host;
114122
// Android considers localhost as 10.0.2.2 - automatically handle this for users.

0 commit comments

Comments
 (0)