firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.51k stars 3.92k forks source link

[firebase_firestore]: Stream does not load value, but future does on web #13019

Closed Albert-Jan closed 3 days ago

Albert-Jan commented 1 week ago

Is there an existing issue for this?

Which plugins are affected?

Cloud Firesotre

Which platforms are affected?

Web

Description

After updating Flutter Firestore from version 4.X to 5.X, the web version, the stream no longer emits a value. Downgrading makes the same code work as expected. The future of the same document works without a problem.

Reproducing the issue

Listen to a stream:

Stream<Project> listenProject(String projectId) => _service.doc(FirestorePath.project(projectId)).snapshots().map((DocumentSnapshot<Map<String, dynamic>> data) => Project.fromMap(data.data()!));

Future loads just fine: Future<Project> getProject(String projectId) async => _service.doc(FirestorePath.project(projectId)).get().then((DocumentSnapshot<Map<String, dynamic>> data) => Project.fromMap(data.data()!));

Firebase Core version

3.1.1

Flutter Version

3.22.2

Relevant Log Output

No error is thrown, even when wrapped with try/catch

Flutter dependencies

No response

Additional context and comments

No response

TarekkMA commented 1 week ago

@Albert-Jan Thank you for reporting this issue. I've replicated the code for the example Firestore app in this branch: issue/13019, and I didn't find any issues. Can you try this branch and see if you still have problems?

Albert-Jan commented 1 week ago

Thanks for your response; I updated my pubspec to rely on the cloud_firestore of the custom branch. I also performed a flutter clean to make sure it was properly compiled.

cloud_firestore: git: url: https://github.com/firebase/flutterfire.git ref: issue/13019 # branch name path: packages/cloud_firestore/cloud_firestore

Unfortunately, it did not work as expected, and the same bug happened. I double checked and downgrading to cloud_firestore: 4.17.4 does work as expected without any code changes.

TarekkMA commented 1 week ago

Can you try running the example app found at this branch and test it with the provided configuration? Then, integrate your Firebase configuration into the example app and test again.

russellwheatley commented 1 week ago

Hey @Albert-Jan - I think I was able to reproduce, fairly sure it is the same as this issue: https://github.com/firebase/flutterfire/pull/13029

Albert-Jan commented 1 week ago

I had a quick look. This might be the problem. Is there a branch I can test this against?

russellwheatley commented 1 week ago

@Albert-Jan Sure, do you mind testing this branch to see if it fixes your issue, please? https://github.com/firebase/flutterfire/tree/firestore-13019

Let me know how it goes 🙏

russellwheatley commented 1 week ago

For testing, I think updating pubspec.yaml to something like this ought to work:

dependencies:
  cloud_firestore_web:
    git:
      url: https://github.com/FirebaseExtended/flutterfire.git
      ref: firestore-13019
      path: packages/cloud_firestore/cloud_firestore_web
russellwheatley commented 4 days ago

@Albert-Jan - did you have a chance to test this?

alextekartik commented 20 hours ago

I still have the issue where registering twice to the same document simply does not work on the web (in debug mode at least)

In my testing I'm listening to 2 documents in 2 locations. It seems subscribing a second time is cancelling the first one (i.e. no more data received on the first subscriber).