Skip to content

SearchAnchor can show stale results when async suggestions complete out of order #190205

Description

@cuishuang

Steps to reproduce

  1. Run the code sample below.
  2. Open the search view.
  3. Type a, then immediately type b, so that the current query becomes ab.
  4. Wait for both asynchronous requests to complete.

The request for a intentionally takes 500 ms, while the request for ab takes only 50 ms.

Expected results

Only the suggestions for the latest query, ab, should be displayed.

Actual results

The ab-result suggestion is displayed first, but is later replaced by the stale a-result when the older request completes.

SearchAnchor.suggestionsBuilder accepts FutureOr<Iterable<Widget>>, but _ViewContentState currently applies every completed result as long as the widget is mounted. It does not verify that the completed request is still the most recent request.

This can also occur between the initial suggestions request started from didChangeDependencies and later requests triggered by controller changes.

RawAutocomplete already avoids the same class of race by assigning a call ID to each asynchronous options request.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(home: SearchAnchorRaceExample()));
}

class SearchAnchorRaceExample extends StatelessWidget {
  const SearchAnchorRaceExample({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SearchAnchor.bar(
          suggestionsBuilder: (
            BuildContext context,
            SearchController controller,
          ) async {
            final String query = controller.text;
            if (query.isEmpty) {
              return <Widget>[];
            }

            await Future<void>.delayed(
              query == 'a'
                  ? const Duration(milliseconds: 500)
                  : const Duration(milliseconds: 50),
            );

            return <Widget>[
              ListTile(title: Text('$query-result')),
            ];
          },
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.41.5, on macOS 26.0 25A8353 darwin-arm64, locale zh-Hans-CN) [88ms]
    • Flutter version 3.41.5 on channel stable at /opt/homebrew/share/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2c9eb20739 (4 months ago), 2026-03-17 16:14:01 -0700
    • Engine revision 052f31d115
    • Dart version 3.11.3
    • DevTools version 2.54.2
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
      cli-animations, enable-native-assets, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [610ms]
    • Android SDK at /Users/mac/Library/Android/sdk
    • Emulator version 36.6.11.0 (build_id 15507667) (CL:N/A)
    • Platform android-36.1, build-tools 36.0.0
    • ANDROID_HOME = /Users/mac/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.10+-117844308-b1163.108)
    • All Android licenses accepted.

[✗] Xcode - develop for iOS and macOS [111ms]
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS and macOS development.
      Download at: https://developer.apple.com/xcode/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods.
      For re-installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation

[✓] Chrome - develop for the web [24ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Proxy Configuration [23ms]
    • HTTP_PROXY is set
    ! NO_PROXY is not set

[✓] Connected device (2 available) [123ms]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 26.0 25A8353 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 150.0.7871.187

[✓] Network resources [1,050ms]
    • All expected network resources are available.

! Doctor found issues in 2 categories.

Activity

  1. added
    in triagePresently being triaged by the triage team
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Jul 30, 2026
  2. suryaKommana2662 commented on Jul 30, 2026

    @suryaKommana2662

    @cuishuang Thanks for report the issue. I was able to reproduce this issue locally on Windows using the provided code sample.
    When I clicked the search bar and quickly typed a followed by b, I observed the suggestions changing from a-result to ab-result and then back to the stale a-result. Routing to the team-design for further investigation.

    search.mp4

    Flutter Doctor Output

    [√] Flutter (Channel stable, 3.44.8, on Microsoft Windows [Version 10.0.26200.8875], locale en-IN) [415ms]
        • Flutter version 3.44.8 on channel stable at C:\flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 058e0af2c2 (6 days ago), 2026-07-23 10:56:21 -0700
        • Engine revision 0cd610717b
        • Dart version 3.12.2
        • DevTools version 2.57.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
          cli-animations, enable-native-assets, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging,
          enable-uiscene-migration
    
    [√] Windows Version (Windows 11 or higher, 25H2, 2009) [1,070ms]
    
    [√] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [3.1s]
        • Android SDK at C:\Android\Sdk
        • Emulator version 36.5.11.0 (build_id 15261927) (CL:N/A)
        • Platform android-36.1, build-tools 36.1.0
        • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.10+-14961533-b1163.108)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web [130ms]
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.6.1) [129ms]
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\18\Community
        • Visual Studio Community 2026 version 18.6.11819.183
        • Windows 10 SDK version 10.0.26100.0
    
    [√] Connected device (3 available) [336ms]
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26200.8875]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 150.0.7871.187
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 150.0.4078.83
    
    [√] Network resources [1,151ms]
        • All expected network resources are available.
    
    • No issues found!
  3. cuishuang commented on Jul 30, 2026

    @cuishuang
    ContributorAuthor

    @cuishuang Thanks for report the issue. I was able to reproduce this issue locally on Windows using the provided code sample. When I clicked the search bar and quickly typed a followed by b, I observed the suggestions changing from a-result to ab-result and then back to the stale a-result. Routing to the team-design for further investigation.

    search.mp4
    Flutter Doctor Output

    [√] Flutter (Channel stable, 3.44.8, on Microsoft Windows [Version 10.0.26200.8875], locale en-IN) [415ms]
    • Flutter version 3.44.8 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 058e0af (6 days ago), 2026-07-23 10:56:21 -0700
    • Engine revision 0cd6107
    • Dart version 3.12.2
    • DevTools version 2.57.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
    cli-animations, enable-native-assets, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging,
    enable-uiscene-migration

    [√] Windows Version (Windows 11 or higher, 25H2, 2009) [1,070ms]

    [√] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [3.1s]
    • Android SDK at C:\Android\Sdk
    • Emulator version 36.5.11.0 (build_id 15261927) (CL:N/A)
    • Platform android-36.1, build-tools 36.1.0
    • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java
    This is the JDK bundled with the latest Android Studio installation on this machine.
    To manually set the JDK path, use: flutter config --jdk-dir="path/to/jdk".
    • Java version OpenJDK Runtime Environment (build 21.0.10+-14961533-b1163.108)
    • All Android licenses accepted.

    [√] Chrome - develop for the web [130ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

    [√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.6.1) [129ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\18\Community
    • Visual Studio Community 2026 version 18.6.11819.183
    • Windows 10 SDK version 10.0.26100.0

    [√] Connected device (3 available) [336ms]
    • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.26200.8875]
    • Chrome (web) • chrome • web-javascript • Google Chrome 150.0.7871.187
    • Edge (web) • edge • web-javascript • Microsoft Edge 150.0.4078.83

    [√] Network resources [1,151ms]
    • All expected network resources are available.

    • No issues found!

    Thank you for reproducing this. I've submitted a pull request to try and fix it; please refer to it. #190206

  4. added
    P2Important issues not at the top of the work list
    triaged-designTriaged by Design Languages team
    on Aug 5, 2026
  5. added
    packageflutter/packages repository. See also p: labels.
    and removed
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Aug 17, 2026
  6. added a commit that references this issue on Aug 27, 2026
    ccd22e1
  7. added 2 commits that reference this issue on Sep 9, 2026
    1e9fae7
    99bb8c1
  8. github-actions commented on Sep 10, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  9. locked as resolved and limited conversation to collaborators on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: material_uimaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.team-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions