Skip to content

Commit

Permalink
fix(cloud_firestore, web): stop FirebaseError appearing in console …
Browse files Browse the repository at this point in the history
…on hot restart & hot refresh (#9321)
  • Loading branch information
russellwheatley committed Aug 11, 2022
1 parent 1aa1c16 commit 4ba0ff9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/cloud_firestore/cloud_firestore/lib/src/firestore.dart
Expand Up @@ -108,7 +108,15 @@ class FirebaseFirestore extends FirebasePluginPlatform {
void useFirestoreEmulator(String host, int port, {bool sslEnabled = false}) {
if (kIsWeb) {
// use useEmulator() API for web as settings are set immediately unlike native platforms
_delegate.useEmulator(host, port);
try {
_delegate.useEmulator(host, port);
} catch (e) {
final String code = (e as dynamic).code;
// this catches FirebaseError from web that occurs after hot reloading & hot restarting
if (code != 'failed-precondition') {
rethrow;
}
}
} else {
String mappedHost = host;
// Android considers localhost as 10.0.2.2 - automatically handle this for users.
Expand Down

0 comments on commit 4ba0ff9

Please sign in to comment.