Skip to content

Commit

Permalink
fix(firestore, web): only set long polling options if it has a value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Sep 10, 2024
1 parent 46b1304 commit 04b5002
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ void main() {
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// Web by default doesn't have persistence enabled
FirebaseFirestore.instance.settings = const Settings(
persistenceEnabled: true,
);

if (kUseFirestoreEmulator) {
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ part of cloud_firestore;

// ignore: do_not_use_environment
const kIsWasm = bool.fromEnvironment('dart.library.js_interop') &&
// html package is not available in wasm
// ignore: do_not_use_environment
bool.fromEnvironment('dart.library.ffi');
!bool.fromEnvironment('dart.library.html');

class _CodecUtility {
static Map<String, dynamic>? replaceValueWithDelegatesInMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
cacheSizeBytes: firestoreSettings.cacheSizeBytes?.toJS,
));
}

JSAny experimentalLongPollingOptions =
firestore_interop.ExperimentalLongPollingOptions(
timeoutSeconds: firestoreSettings.webExperimentalLongPollingOptions
?.timeoutDuration?.inSeconds.toJS) as JSAny;

if (firestoreSettings.host != null &&
firestoreSettings.sslEnabled != null) {
_interopSettings = firestore_interop.FirestoreSettings(
Expand All @@ -167,7 +161,6 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
firestoreSettings.webExperimentalForceLongPolling?.toJS,
experimentalAutoDetectLongPolling:
firestoreSettings.webExperimentalAutoDetectLongPolling?.toJS,
experimentalLongPollingOptions: experimentalLongPollingOptions,
ignoreUndefinedProperties:
firestoreSettings.ignoreUndefinedProperties.toJS,
);
Expand All @@ -178,11 +171,22 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
firestoreSettings.webExperimentalForceLongPolling?.toJS,
experimentalAutoDetectLongPolling:
firestoreSettings.webExperimentalAutoDetectLongPolling?.toJS,
experimentalLongPollingOptions: experimentalLongPollingOptions,
ignoreUndefinedProperties:
firestoreSettings.ignoreUndefinedProperties.toJS,
);
}
if (firestoreSettings.webExperimentalLongPollingOptions != null) {
// If this is null, it will throw an exception when initializing the Firestore instance via interop
JSAny experimentalLongPollingOptions =
firestore_interop.ExperimentalLongPollingOptions(
timeoutSeconds: firestoreSettings
.webExperimentalLongPollingOptions
?.timeoutDuration
?.inSeconds
.toJS) as JSAny;
_interopSettings?.experimentalLongPollingOptions =
experimentalLongPollingOptions;
}
}

/// Enable persistence of Firestore data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ extension FirestoreSettingsExtension on FirestoreSettings {
/// Union type MemoryLocalCache | PersistentLocalCache;
//ignore: avoid_setters_without_getters
external set localCache(JSObject u);

external set experimentalLongPollingOptions(JSAny v);
}

/// Options that configure the SDK’s underlying network transport (WebChannel) when long-polling is used
Expand Down

0 comments on commit 04b5002

Please sign in to comment.