Skip to content

Commit

Permalink
fix(core): Omit unnecessary libraries for web (#10068)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Terwesten <gabriel@terwesten.net>
  • Loading branch information
kaptnkoala and blaugold committed Jun 12, 2023
1 parent c8b685b commit 8659d4e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 33 deletions.
Expand Up @@ -6,9 +6,9 @@ import 'dart:async';

import 'package:firebase_app_check_platform_interface/firebase_app_check_platform_interface.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:firebase_core_web/firebase_core_web_interop.dart'
as core_interop;
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';

import 'src/internals.dart';
Expand All @@ -28,7 +28,10 @@ class FirebaseAppCheckWeb extends FirebaseAppCheckPlatform {

/// Called by PluginRegistry to register this plugin for Flutter Web
static void registerWith(Registrar registrar) {
FirebaseCoreWeb.registerService('app-check');
FirebaseCoreWeb.registerService(
'app-check',
productNameOverride: 'app_check',
);
FirebaseAppCheckPlatform.instance = FirebaseAppCheckWeb.instance;
}

Expand Down
49 changes: 26 additions & 23 deletions packages/firebase_auth/firebase_auth_web/lib/firebase_auth_web.dart
Expand Up @@ -91,35 +91,38 @@ class FirebaseAuthWeb extends FirebaseAuthPlatform {

/// Called by PluginRegistry to register this plugin for Flutter Web
static void registerWith(Registrar registrar) {
FirebaseCoreWeb.registerService('auth', (firebaseApp) async {
final authDelegate = auth_interop.getAuthInstance(firebaseApp);
// if localhost, and emulator was previously set in localStorage, use it
if (window.location.hostname == 'localhost' && kDebugMode) {
final String? emulatorOrigin =
window.sessionStorage[getOriginName(firebaseApp.name)];

if (emulatorOrigin != null) {
try {
authDelegate.useAuthEmulator(emulatorOrigin);
// ignore: avoid_print
print(
'Using previously configured Auth emulator at $emulatorOrigin for ${firebaseApp.name} \nTo switch back to production, restart your app with the emulator turned off.',
);
} catch (e) {
if (e.toString().contains('sooner')) {
// Happens during hot reload when the emulator is already configured
FirebaseCoreWeb.registerService(
'auth',
ensurePluginInitialized: (firebaseApp) async {
final authDelegate = auth_interop.getAuthInstance(firebaseApp);
// if localhost, and emulator was previously set in localStorage, use it
if (window.location.hostname == 'localhost' && kDebugMode) {
final String? emulatorOrigin =
window.sessionStorage[getOriginName(firebaseApp.name)];

if (emulatorOrigin != null) {
try {
authDelegate.useAuthEmulator(emulatorOrigin);
// ignore: avoid_print
print(
'Auth emulator is already configured at $emulatorOrigin for ${firebaseApp.name} and kept across hot reload.\nTo switch back to production, restart your app with the emulator turned off.',
'Using previously configured Auth emulator at $emulatorOrigin for ${firebaseApp.name} \nTo switch back to production, restart your app with the emulator turned off.',
);
} else {
rethrow;
} catch (e) {
if (e.toString().contains('sooner')) {
// Happens during hot reload when the emulator is already configured
// ignore: avoid_print
print(
'Auth emulator is already configured at $emulatorOrigin for ${firebaseApp.name} and kept across hot reload.\nTo switch back to production, restart your app with the emulator turned off.',
);
} else {
rethrow;
}
}
}
}
}
await authDelegate.onWaitInitState();
});
await authDelegate.onWaitInitState();
},
);
FirebaseAuthPlatform.instance = FirebaseAuthWeb.instance;
PhoneMultiFactorGeneratorPlatform.instance = PhoneMultiFactorGeneratorWeb();
RecaptchaVerifierFactoryPlatform.instance =
Expand Down
Expand Up @@ -14,7 +14,7 @@ class FirebaseWebService {
/// property allows overriding of web naming to Flutterfire plugin naming.
String? override;

/// Function to call to ensure the Firebase Service is initalized.
/// Function to call to ensure the Firebase Service is initialized.
/// Usually used to ensure that the Web SDK match the behavior
/// of native SDKs.
EnsurePluginInitialized ensurePluginInitialized;
Expand All @@ -37,20 +37,19 @@ typedef EnsurePluginInitialized = Future<void> Function(
class FirebaseCoreWeb extends FirebasePlatform {
static Map<String, FirebaseWebService> _services = {
'core': FirebaseWebService._('app', override: 'core'),
'app-check': FirebaseWebService._('app-check', override: 'app_check'),
'remote-config':
FirebaseWebService._('remote-config', override: 'remote_config'),
};

/// Internally registers a Firebase Service to be initialized.
static void registerService(
String service, [
String service, {
String? productNameOverride,
EnsurePluginInitialized? ensurePluginInitialized,
]) {
}) {
_services.putIfAbsent(
service,
() => FirebaseWebService._(
service,
override: productNameOverride,
ensurePluginInitialized: ensurePluginInitialized,
),
);
Expand All @@ -73,7 +72,7 @@ class FirebaseCoreWeb extends FirebasePlatform {
}

/// Returns a list of services which won't be automatically injected on
/// initilization. This is useful incases where you wish to manually include
/// initialization. This is useful incases where you wish to manually include
/// the scripts (e.g. in countries where you must request the users permission
/// to include Analytics).
///
Expand Down
Expand Up @@ -34,7 +34,10 @@ class FirebaseRemoteConfigWeb extends FirebaseRemoteConfigPlatform {

/// Create the default instance of the [FirebaseRemoteConfigPlatform] as a [FirebaseRemoteConfigWeb]
static void registerWith(Registrar registrar) {
FirebaseCoreWeb.registerService('remote-config');
FirebaseCoreWeb.registerService(
'remote-config',
productNameOverride: 'remote_config',
);
FirebaseRemoteConfigPlatform.instance = FirebaseRemoteConfigWeb.instance;
}

Expand Down

0 comments on commit 8659d4e

Please sign in to comment.