Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 FirestoreListView renders (incomplete) local cache before remote db result #238

Open
1 task done
sinnaj-r opened this issue Jan 4, 2024 · 9 comments
Open
1 task done
Assignees
Labels
blocked: customer response Waiting for customer response, e.g. more information was requested. bug Something isn't working firestore

Comments

@sinnaj-r
Copy link

sinnaj-r commented Jan 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues and found no duplicates.

What plugin is this bug for?

Firebase UI Firestore

What platform(s) does this bug affect?

Web

List of dependencies used.

flutter pub deps -s list
Our dependency list is very long, and contains private packages, therefore I only include the relevant firebase packages here:


- firebase_core 2.21.0
  - firebase_core_platform_interface ^5.0.0
  - firebase_core_web ^2.8.1
  - flutter any
  - meta ^1.8.0
- firebase_auth 4.12.1
  - firebase_auth_platform_interface ^7.0.3
  - firebase_auth_web ^5.8.6
  - firebase_core ^2.21.0
  - firebase_core_platform_interface ^5.0.0
  - flutter any
  - meta ^1.8.0
- firebase_messaging 14.7.3
  - firebase_core ^2.21.0
  - firebase_core_platform_interface ^5.0.0
  - firebase_messaging_platform_interface ^4.5.12
  - firebase_messaging_web ^3.5.12
  - flutter any
  - meta ^1.8.0
- firebase_crashlytics 3.4.3
  - firebase_core ^2.21.0
  - firebase_core_platform_interface ^5.0.0
  - firebase_crashlytics_platform_interface ^3.6.11
  - flutter any
  - stack_trace ^1.10.0
- cloud_firestore 4.12.2
  - cloud_firestore_platform_interface ^6.0.3
  - cloud_firestore_web ^3.8.3
  - collection ^1.0.0
  - firebase_core ^2.21.0
  - firebase_core_platform_interface ^5.0.0
  - flutter any
  - meta ^1.8.0
- firebase_ui_firestore ^1.5.7

Steps to reproduce

  • Do not enable Persistance on Web (default is -- as far as I know -- a small memory cache)
  • Have .snapshots()-Stream on a single firestore document (lets call it docA ); Render this document e.g. with a StreamBuilder.
  • Next to that use the FirestoreListView to render a list of documents (including docA ). The database should contain enough documents, to allow for multiple pages.
  • Scroll down the FirestoreListView to trigger the "fetch more" functionality.
  • Now the FirestoreListView will render a list only containing docA for a very short amount of time and then render the full list. This results in the scroll position beeing lost and the whole list apparently jumping to the top.

Expected Behavior

I would expect the List not jumping. And thereby, as far as I understood the bug, I would expect the list not rendering a single cached item inbetween list fetches. I would also be fine with disabling any caching behavior on web, if there's a way to do that.

Actual Behavior

(see steps to reproduce)

Additional Information

I briefly looked into the FirestoreListView code (packages/firebase_ui_firestore/lib/src/query_builder.dart) . If I'm not mistaken, the problems lies in the query.snapshots().listen()-Callback in lines 176 et seq. Here any data is "rendered", as long as its smaller then expectedDocsCount, which of course includes the one item eagerly returned by the cache.

@danagbemava-nc
Copy link
Contributor

Labeling based on the report above, I keep hitting #239

@danagbemava-nc danagbemava-nc added bug Something isn't working firestore and removed in triage labels Jan 5, 2024
@sinnaj-r
Copy link
Author

Labeling based on the report above, I keep hitting #239

Are you able to reproduce the bug now that #239 is fixed ? Otherwise I can gladly provide more information.

@russellwheatley
Copy link
Member

Scratched my head on this issue for a while, it turns out, this appears to be a bug in the firebase-js-sdk. I will open a bug report on that repo and link to this issue 馃憤

@russellwheatley
Copy link
Member

Opened issue here if you wish to track: firebase/firebase-js-sdk#8004

@russellwheatley russellwheatley added the blocked: firebase-sdk blocked due to underlying Firebase SDK label Feb 2, 2024
@adifyr
Copy link

adifyr commented Feb 15, 2024

Hi. Do you have any updates on this? I am utilizing a FirestoreListView while also listening to a specific document using StreamProvider on Riverpod. And I'm facing this issue.

The JS sdk isue got closed as it was concluded that the issue wasn't there. What's the issue exactly? And is there an interim solution in the meantime?

@russellwheatley
Copy link
Member

the interim solution is to update your cache settings so persistenceEnabled is set to true:

  FirebaseFirestore.instance.settings = const Settings(
    persistenceEnabled: true,
  );

I'm trying to figure out the optimal solution to this problem in the underlying implementation.

@russellwheatley russellwheatley removed the blocked: firebase-sdk blocked due to underlying Firebase SDK label Feb 20, 2024
@russellwheatley
Copy link
Member

russellwheatley commented Apr 12, 2024

@sinnaj-r - I actually think the solution to this problem is to set persistence:

  FirebaseFirestore.instance.settings = const Settings(
    persistenceEnabled: true,
  );

That way, you're matching the persistence that you see on the native SDKs which have persistence enabled by default. FlutteFire has also fixed the hot restart bug so it no longer crashes.

@russellwheatley russellwheatley added bug Something isn't working blocked: customer response Waiting for customer response, e.g. more information was requested. and removed bug Something isn't working labels Apr 12, 2024
@sinnaj-r
Copy link
Author

@sinnaj-r - I actually think the solution to this problem is to set persistence:

  FirebaseFirestore.instance.settings = const Settings(
    persistenceEnabled: true,
  );

That way, you're matching the persistence that you see on the native SDKs which have persistence enabled by default. FlutteFire has also fixed the hot restart bug so it no longer crashes.

Thank you for the response; unfortunately, at least in our use case, activating persistence is not something we can do because our application is used by many "office"-type PCs with very limited resources that can not deal with the app taking up several hundreds of megabytes (or more) of RAM -- which is what we observed after enabling persistence.

@russellwheatley
Copy link
Member

Have you tried limiting cache size:

FirebaseFirestore.instance.settings = const Settings(
    persistenceEnabled: true,
	// Limit cache size to whatever you want
    cacheSizeBytes: 10000,
  );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer response Waiting for customer response, e.g. more information was requested. bug Something isn't working firestore
Projects
None yet
Development

No branches or pull requests

5 participants