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.68k stars 3.97k forks source link

🐛 [cloud_firestore] Wrong Pagination Flutter Web: startAfterDocument is always returning the same document indicated as the pointer #11613

Closed christenbc closed 10 months ago

christenbc commented 1 year ago

Bug report

Describe the bug startAfterDocument is always returning the same document indicated as the pointer for Flutter Web if it is the final result. However, this issue is not present for macOS.

Steps to reproduce

  @override
  Future<List<Trip>> fetchTrips({required String agencyId, String? lastTripId, int? batchSize}) async {
    QuerySnapshot tripsSnapshot;

    final refTrips = _firebaseFirestore
        .collection(APIPaths.trips)
        .where('fromAgencyId', isEqualTo: agencyId)
        .orderBy('creation', descending: true)
        .limit(batchSize ?? 3);

    if (lastTripId == null) {
      tripsSnapshot = await refTrips.get();
    } else {
      final lastTripDoc = await _firebaseFirestore.collection(APIPaths.trips).doc(lastTripId).get();

      if (!lastTripDoc.exists) {
        return [];
      }

      tripsSnapshot = await refTrips
          .startAfterDocument(lastTripDoc)
          .get(); // this is problematic on web as it is always fetching the last
    }

    final trips = tripsSnapshot.docs.mapToList((doc) => Trip.fromDocument(doc));
    return Future.wait(trips);
  }

Expected behavior

tripsSnapshot = await refTrips
          .startAfterDocument(lastTripDoc)
          .get();

this should not return the same lastTripDoc, but the document after.

Sample project

Providing a minimal example project which demonstrates the bug in isolation from your main App greatly enhances the chance of a timely fix. Please link to the public repository URL.


Additional context

Add any other context about the problem here.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [✓] Flutter (Channel stable, 3.13.0, on macOS 13.5.2 22G91 darwin-arm64, locale en-ES) • Flutter version 3.13.0 on channel stable at /Users/christen/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision efbf63d9c6 (5 weeks ago), 2023-08-15 21:05:06 -0500 • Engine revision 1ac611c64e • Dart version 3.1.0 • DevTools version 2.25.0 [!] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /Users/christen/Library/Android/sdk ✗ cmdline-tools component is missing Run `path/to/sdkmanager --install "cmdline-tools;latest"` See https://developer.android.com/studio/command-line for more details. ✗ Android license status unknown. Run `flutter doctor --android-licenses` to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/macos#android-setup for more details. [✓] Xcode - develop for iOS and macOS (Xcode 15.0) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15A240d • CocoaPods version 1.12.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) [✓] VS Code (version 1.82.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.72.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-arm64 • macOS 13.5.2 22G91 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 116.0.5845.187 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` Dart SDK 3.1.0 Flutter SDK 3.13.0 destinno_backoffice 1.0.0+1 dependencies: - core 0.0.1 [flutter cloud_firestore dartx enum_to_string equatable google_fonts intl localization share_plus flutter_svg go_router url_launcher font_awesome_flutter printing cached_network_image elegant_notification pdf flutter_bloc firebase_auth firebase_storage cloud_functions firebase_core video_player] - crop_image 1.0.10 [flutter] - cupertino_icons 1.0.5 - file_picker 5.3.2 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32] - flutter 0.0.0 [characters collection material_color_utilities meta vector_math web sky_engine] - flutter_bloc 8.1.3 [bloc flutter provider] - flutter_dotenv 5.1.0 [flutter] - flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math web] - flutter_rating_bar 4.0.1 [flutter] - go_router 10.2.0 [collection flutter flutter_web_plugins logging meta] - localization 2.1.0 [flutter] - rxdart 0.27.7 - unsplash_client 2.1.1 [meta http collection logging] - url_strategy 0.2.0 [flutter_web_plugins] - video_player 2.7.1 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] dev dependencies: - flutter_launcher_icons 0.13.1 [args checked_yaml cli_util image json_annotation path yaml] - flutter_lints 2.0.3 [lints] - flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math async boolean_selector characters collection material_color_utilities meta source_span stream_channel string_scanner term_glyph web] transitive dependencies: - _flutterfire_internals 1.3.5 [collection firebase_core firebase_core_platform_interface flutter meta] - archive 3.3.7 [crypto path pointycastle] - args 2.4.2 - async 2.11.0 [collection meta] - barcode 2.2.4 [meta qr] - bidi 2.0.7 - bloc 8.1.2 [meta] - boolean_selector 2.1.1 [source_span string_scanner] - cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cached_network_image_platform_interface 2.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.2 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.3.0 - checked_yaml 2.0.3 [json_annotation source_span yaml] - cli_util 0.4.0 [meta path] - clock 1.1.1 - cloud_firestore 4.9.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cloud_firestore_platform_interface 5.16.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.7.0 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - cloud_functions 4.4.0 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter] - cloud_functions_platform_interface 5.5.0 [firebase_core flutter meta plugin_platform_interface] - cloud_functions_web 4.6.0 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.17.2 - convert 3.1.1 [typed_data] - cross_file 0.3.3+4 [js meta] - crypto 3.0.3 [typed_data] - csslib 1.0.0 [source_span] - dartx 1.2.0 [characters collection crypto meta path time] - elegant_notification 1.11.1 [flutter] - enum_to_string 2.0.1 - equatable 2.0.5 [collection meta] - fake_async 1.3.1 [clock collection] - ffi 2.0.2 - file 6.1.4 [meta path] - firebase_auth 4.9.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_auth_platform_interface 6.18.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.8.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta] - firebase_core 2.15.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.7.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_storage 11.2.6 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter] - firebase_storage_platform_interface 4.4.5 [collection firebase_core flutter meta plugin_platform_interface] - firebase_storage_web 3.6.6 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta] - flutter_blurhash 0.7.0 [flutter] - flutter_cache_manager 3.3.1 [clock collection file flutter http path path_provider rxdart sqflite uuid] - flutter_plugin_android_lifecycle 2.0.15 [flutter] - flutter_svg 2.0.7 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math web] - font_awesome_flutter 10.5.0 [flutter] - google_fonts 6.0.0 [flutter http path_provider crypto] - html 0.15.4 [csslib source_span] - http 1.1.0 [async http_parser meta] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 4.0.17 [archive meta xml] - intl 0.18.1 [clock meta path] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - lints 2.1.1 - logging 1.2.0 - matcher 0.12.16 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.5.0 [collection] - meta 1.9.1 - mime 1.0.4 - nested 1.0.0 [flutter] - octo_image 1.0.2 [flutter flutter_blurhash] - path 1.8.3 - path_parsing 1.0.1 [vector_math meta] - path_provider 2.0.15 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.0.27 [flutter path_provider_platform_interface] - path_provider_foundation 2.2.3 [flutter path_provider_platform_interface] - path_provider_linux 2.1.11 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.6 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.7 [ffi flutter path path_provider_platform_interface win32] - pdf 3.10.4 [archive barcode bidi crypto image meta path_parsing vector_math xml] - petitparser 5.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.4 [meta] - pointycastle 3.7.3 [collection convert js] - printing 5.11.0 [ffi flutter flutter_web_plugins http image js meta pdf plugin_platform_interface] - process 4.2.4 [file path platform] - provider 6.0.5 [collection flutter nested] - qr 3.0.1 [meta] - share_plus 7.1.0 [cross_file meta mime flutter flutter_web_plugins share_plus_platform_interface file url_launcher_web url_launcher_windows url_launcher_linux url_launcher_platform_interface ffi win32] - share_plus_platform_interface 3.3.0 [cross_file flutter meta mime plugin_platform_interface path_provider uuid] - sky_engine 0.0.99 - source_span 1.10.0 [collection path term_glyph] - sqflite 2.2.8+4 [flutter sqflite_common path] - sqflite_common 2.4.5+1 [synchronized path meta] - stack_trace 1.11.0 [path] - stream_channel 2.1.1 [async] - string_scanner 1.2.0 [source_span] - synchronized 3.1.0 - term_glyph 1.2.1 - test_api 0.6.0 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph] - time 2.1.3 [clock] - typed_data 1.3.2 [collection] - url_launcher 6.1.14 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_launcher_android 6.1.0 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.5 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.5 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.7 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.3 [flutter plugin_platform_interface] - url_launcher_web 2.0.18 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.7 [flutter url_launcher_platform_interface] - uuid 3.0.7 [crypto] - vector_graphics 1.1.7 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.7 - vector_graphics_compiler 1.1.7 [args meta path_parsing xml vector_graphics_codec] - vector_math 2.1.4 - video_player_android 2.4.10 [flutter video_player_platform_interface] - video_player_avfoundation 2.4.10 [flutter video_player_platform_interface] - video_player_platform_interface 6.2.1 [flutter plugin_platform_interface] - video_player_web 2.1.0 [flutter flutter_web_plugins video_player_platform_interface] - web 0.1.4-beta - win32 5.0.5 [ffi] - xdg_directories 1.0.0 [meta path process] - xml 6.3.0 [collection meta petitparser] - yaml 3.1.2 [collection source_span string_scanner] ```

darshankawar commented 1 year ago

@chbloca I am wondering if this is an issue with JavaScript rather than in flutterfire. You might need to try with orderBy() and see if it works as intended ?

christenbc commented 1 year ago

OrderBy has no effect whatsoever

darshankawar commented 1 year ago

Thanks for checking. Can you provide us a runnable reproducible code sample that we can directly use to verify this behavior ?

Also check if this helps in your case or not.

christenbc commented 1 year ago

Unfortunately, I am not able to provide a runnable code.

darshankawar commented 1 year ago

Also check if this helps in your case or not.

Did you get a chance to look at this and check if it helps ?

google-oss-bot commented 1 year ago

Hey @chbloca. 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!

christenbc commented 1 year ago

That is a different method and is out of the scope of this thread. The issue is related to .starAfterDocument(), not in .startAfter(). If you don't feel like to work on this, maybe you should delegate it to another Flutter employee.

darshankawar commented 1 year ago

Thanks for the update.

If you don't feel like to work on this, maybe you should delegate it to another Flutter employee.

By providing the links earlier, I was trying to see if they could be helpful or not. So it is not about what you mentioned.

Also, when I tried using the plugin example, I wasn't able to replicate the behavior, so asked for reproducible code sample which is important to debug further. Since you can't provide one based on your comment, I will label it for team' attention.

/cc @russellwheatley

russellwheatley commented 10 months ago

I've tested locally and I cannot reproduce. We also run in our integration tests here.

Will reopen if there is a way of reproducing, closing out until it is provided.