-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🐛 [cloud_firestore] experimentalForceLongPolling
option
#11149
Comments
@jbaptisteroesch |
@darshankawar when trying the given answer in the issue, I'm facing multiple errors (see screen below). index.html (pastebin): |
Although https://www.reddit.com/r/Firebase/comments/uw6qa8/cloud_functions_unexpected_token_export/ isn't related to |
The Reddit post wasn't particularly helpful, but I tried another solution that didn't return any errors on my end. Here's the code:
However, I have a minor concern about it. I couldn't find any other place than the index.html file to store the |
Thanks for the update @jbaptisteroesch https://firebase.google.com/docs/functions/config-env?gen=2nd |
Sorry @darshankawar I think your missing the issue here. We are having the same underlying issue which was fixed by setting The issue we have is that Other settings such as 'enablePersistence' and 'cacheSizeBytes' are exposed, 'experimentalForceLongPolling' is not. Thanks Edit: apologues I've just dug through the source |
I've been digging through the docs and source code, amazingly 4 days ago version 4.8.2 was released which updated the underlying sdk which now has @jbaptisteroesch that may have fixed your problem. However I still think its a good idea to have these settings exposed in the dart lib. |
@darshankawar thanks to this post found on stackoverlow I was able to fix the exposed key issue. However, now that this seems to work, I have a message in the console:
Does this means that i don't need to initialize Firebase in my main.dart? You can find below my code in the two files. index.html
main.dart
@willcalderbank I was enable to find a part of code related to this issue in the 4.8.2 version in this PR. |
@jbaptisteroesch That console message has always been there for us. I think the issue is that you do need to initialize your app in main, which will override the settings, but maybe you can get away with not doing so if you don't also support mobile apps. Haven't tried that because our app is cross-platform. But we've run into the same issue. A lot of our users work for companies with strict network security, so I'm going to leave the
Btw we haven't rolled this into production yet, but I have confirmed that the network requests are following the long polling pattern. We plan to roll out a release including this in the next couple of weeks. Here's what you need to add to your dependency_overrides:
# Override to allow for experimentalForceLongPolling
cloud_firestore:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore
ref: fcd904c983309213b90bf2d66826899c89ef5f73
cloud_firestore_platform_interface:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_platform_interface
ref: fcd904c983309213b90bf2d66826899c89ef5f73
cloud_firestore_web:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_web
ref: fcd904c983309213b90bf2d66826899c89ef5f73 And then in your await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
FirebaseFirestore.instance.settings = Settings(
experimentalForceLongPolling: true,
); |
Thanks for the updates. Based on the reports and feedback, keeping this issue open for team's input. /cc @russellwheatley |
Oh, it seems this solution does not work anymore, at least in my situation. This is my updated pubspec dependency_overrides:
# Override to allow for experimentalForceLongPolling
cloud_firestore:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore
ref: dc2f319478b246f41619c818103ae3f86dd8d36f
cloud_firestore_platform_interface:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_platform_interface
ref: dc2f319478b246f41619c818103ae3f86dd8d36f
cloud_firestore_web:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_web
ref: dc2f319478b246f41619c818103ae3f86dd8d36f I confirm that when I write a JS app with firebase-js-sdk and turn on this option, it works. But this does not for my Flutter app. Am I doing something wrong? |
Hi @vietstone-ng, it looks like you got this working on a custom fork? Let me know if you are still having troubles and I can share my new SHAs with you. I recently updated my fork. |
@jcwasher I tried to replicate your work on When I tried to create a JS app and turn on this option, it works as described in firebase/firebase-js-sdk#1674 (comment). But no luck with Flutter. |
@vietstone-ng Sure, here are my latest. dependency_overrides:
cloud_firestore:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore
ref: dc2f319478b246f41619c818103ae3f86dd8d36f
cloud_firestore_platform_interface:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_platform_interface
ref: dc2f319478b246f41619c818103ae3f86dd8d36f
cloud_firestore_web:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_web
ref: dc2f319478b246f41619c818103ae3f86dd8d36f |
@jcwasher Thank you very much. But it does not work in my situation. I opened Chrome's dev tool and saw that the settings are passed correctly to JS layer, but the error still happens. Below is my pubspec: # pubspec.yaml
...
dependencies:
# Firebase
firebase_core: ^2.24.2
firebase_auth: ^4.16.0
firebase_messaging: ^14.7.10
cloud_firestore: ^4.14.0
firebase_crashlytics: ^3.4.9
cloud_functions: ^4.6.0
firebase_storage: ^11.6.7
firebase_remote_config: ^4.3.15
# Firebase web
firebase_core_web: 2.12.0
firebase_auth_web: ^5.8.13
firebase_messaging_web: ^3.5.18
cloud_firestore_web: ^3.9.0
cloud_functions_web: ^4.6.11
dependency_overrides:
cloud_firestore:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore
ref: dc2f319478b246f41619c818103ae3f86dd8d36f
cloud_firestore_platform_interface:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_platform_interface
ref: dc2f319478b246f41619c818103ae3f86dd8d36f
cloud_firestore_web:
git:
url: https://github.com/jcwasher/flutterfire.git
path: packages/cloud_firestore/cloud_firestore_web
ref: dc2f319478b246f41619c818103ae3f86dd8d36f
... The attached image is my devtool where JS's and the log: Launching lib/main.dart on Chrome in debug mode...
This app is linked to the debug service: ws://127.0.0.1:63126/JM2sWtLQWk0=/ws
Debug service listening on ws://127.0.0.1:63126/JM2sWtLQWk0=/ws
Connecting to VM Service at ws://127.0.0.1:63126/JM2sWtLQWk0=/ws
WARNING: found an existing <meta name="viewport"> tag. Flutter Web uses its own viewport configuration for better compatibility with Flutter. This tag will be replaced.
[2024-04-11T06:50:33.053Z] @firebase/firestore:
Bad state: No element
[cloud_firestore/unavailable] Failed to get document because the client is offline.
Error: TypeError: null: type 'Null' is not a subtype of type 'Map<dynamic, dynamic>'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3 throw_
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1385:3 _failedAsCheck
dart-sdk/lib/_internal/js_shared/lib/rti.dart 1363:3 _generalAsCheckImplementation
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn>
dart-sdk/lib/async/zone.dart 1661:54 runUnary
dart-sdk/lib/async/future_impl.dart 162:18 handleValue
dart-sdk/lib/async/future_impl.dart 838:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 867:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 643:5 [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 713:7 callback
dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7 <fn>
[2024-04-11T06:50:41.978Z] @firebase/firestore: I also noticed that the JS's But it does not work in my situation. Can someone help me to check what problem is happening? |
@vietstone-ng A few questions...
Here are the versions I'm specifying for my other Firebase packages. Fwiw I'm not using some of the others that you are: cloud_firestore: 4.15.9
firebase_auth: 4.17.9
firebase_core: 2.27.1 Note it may be helpful to not use the |
@jcwasher Thank you very much for your time. I used So the problem seems the JS code does not work in my situation, not Dart code |
My customers are getting the same error from your last log "Failed to get document because the client is offline." on certain corporate networks. In my case it is on Flutter Windows |
Users on certain corporate networks are experiencing the issue,
Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
likely due to proxies, ad blockers, etc. This issue is known and the team is currently addressing it in the Firebase JS SDK. See: firebase/firebase-js-sdk#1674.However, it appears no similar action has been taken on the Flutter SDK. An issue was raised a few months ago, but was quickly closed without a definitive resolution. See: #10534.
The options
experimentalForceLongPolling
orexperimentalAutoDetectLongPolling
do not appear to be available in the cloud_firestore plugin (v4.8.1).Did I overlook something, is it a planned feature, or does it not exist at all? Is there a workaround if these settings are unavailable?
The issue is difficult to reproduce and highly situational. I was previously unaware of the problem and am finding it challenging to consider moving the project to another backend service.
Thank you in advance for any assistance.
The text was updated successfully, but these errors were encountered: