Skip to content

Commit c3dc98b

Browse files
committed
fix(web): skip Remote Config realtime stream on web
The CachedRemoteConfigService constructor subscribed to FirebaseRemoteConfig.onConfigUpdated with no onError handler. On web that realtime stream cannot connect and emits `remoteconfig/stream-error` continuously, so the errors escaped to runZonedGuarded and spammed SEVERE every few seconds. Skip the realtime subscription on web (config values still come from init's bounded fetch and the cache), and add an onError handler so a transient stream error no longer escapes to the zone on native either.
1 parent 37d966c commit c3dc98b

1 file changed

Lines changed: 24 additions & 15 deletions

File tree

lib/services/remote_config_service.dart

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,30 @@ abstract class RemoteCacheConfigService {
7070
/// Implementation of [RemoteConfigService] using Firebase Remote Config.
7171
class CachedRemoteConfigService implements RemoteConfigService {
7272
CachedRemoteConfigService(this._cacheService, this._remoteConfig) {
73-
_onConfigUpdatedSubscription = _remoteConfig.onConfigUpdated.listen((event) async {
74-
_logger.info('Remote config update signal received. Updated keys: ${event.updatedKeys}');
75-
try {
76-
await _remoteConfig.activate();
77-
78-
// Guard against calling add/unawaited logic after the service is disposed.
79-
if (_controller.isClosed) return;
80-
81-
final snapshot = _createSnapshot();
82-
_controller.add(snapshot);
83-
unawaited(_updateCache(snapshot));
84-
} catch (e, stackTrace) {
85-
_logger.warning('Failed to activate remote config update', e, stackTrace);
86-
}
87-
});
73+
// Firebase Remote Config realtime updates are not available on web: the
74+
// stream cannot connect and emits `remoteconfig/stream-error` continuously.
75+
// Skip the subscription there - values still come from init's fetch and the
76+
// cache. TODO(web): revisit if RC realtime ever works on web.
77+
if (kIsWeb) return;
78+
_onConfigUpdatedSubscription = _remoteConfig.onConfigUpdated.listen(
79+
(event) async {
80+
_logger.info('Remote config update signal received. Updated keys: ${event.updatedKeys}');
81+
try {
82+
await _remoteConfig.activate();
83+
84+
// Guard against calling add/unawaited logic after the service is disposed.
85+
if (_controller.isClosed) return;
86+
87+
final snapshot = _createSnapshot();
88+
_controller.add(snapshot);
89+
unawaited(_updateCache(snapshot));
90+
} catch (e, stackTrace) {
91+
_logger.warning('Failed to activate remote config update', e, stackTrace);
92+
}
93+
},
94+
// Without this, a transient realtime-stream error escapes to the zone.
95+
onError: (Object e, StackTrace s) => _logger.warning('Remote config update stream error', e, s),
96+
);
8897
}
8998

9099
final FirebaseRemoteConfig _remoteConfig;

0 commit comments

Comments
 (0)