-
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]: setState Causes snapshot.data.docChanges to Reinitialize Without Actual Firestore Changes. #12901
Comments
Hello @abineshPalanisamy Thank you for sharing an issue. I see that Can you refactor this and test atain? |
Hi @TarekkMA When setState is called, We performed logic in the Regards, |
Calling |
Hey @abineshPalanisamy. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically. If you have more information that will help us get to the bottom of this, just add a comment! |
Hi @TarekkMA , I believe that the According to the previous response, when setState is called, snapshot.data.docChanges gets reinitialized and behaves as if it is the initial loading by providing all the documents in the Firestore collection with the type DocumentChangeType.added. This is the root cause of the issue. My concern is why Regards, |
Hey @abineshPalanisamy - The reason this is occurring is because setState refreshes the stream listener and the last event is published. The last event contains all the docChanges i.e. the initial load. To test, you can add a document to the collection in the console and you will see the docChanges contains only 1 change now, each time you press the button, you will now see 1 change. I advise you not to setState where you're listening to the stream otherwise it will continue to refresh listening to the stream and the docChanges will always contain the changes from the last time the collection was updated. |
Is there an existing issue for this?
Which plugins are affected?
Other
Which platforms are affected?
Android, iOS, macOS, Web, Windows
Description
When the application rebuilds using setState, the StreamBuilder reinitializes, causing snapshot.data.docChanges to act as if it is the initial loading. This can result in the provides duplicate values in the list based on snapshot.data.docChanges without any actual changes in Firestore.
flutter_application_1.2024-06-04.17-39-45.mp4
Reproducing the issue
Firebase Core version
3.0.0
Flutter Version
3.22.1
Relevant Log Output
No response
Flutter dependencies
Expand
Flutter dependencies
snippetAdditional context and comments
No response
The text was updated successfully, but these errors were encountered: