Skip to content

RichText keeps a stale semantics label when only TextSpan.semanticsLabel or locale changes #195755

Description

@ChandraChaan

Steps to reproduce

testWidgets('stale semantics label', (WidgetTester tester) async {
  final SemanticsHandle handle = tester.ensureSemantics();
  Widget build(String label) => Directionality(
    textDirection: TextDirection.ltr,
    child: RichText(text: TextSpan(text: 'hello', semanticsLabel: label)),
  );
  await tester.pumpWidget(build('first'));
  await tester.pumpWidget(build('second'));
  expect(tester.getSemantics(find.byType(RichText)).label, 'second');
  handle.dispose();
});

Expected results

The semantics label is second, so a screen reader announces the new label.

Actual results

The label stays first. The same happens when only locale changes (the LocaleStringAttribute keeps the old locale), and for semanticsIdentifier and spellOut.

TextSpan.compareTo only looks at recognizer for metadata changes, so it returns RenderComparison.identical and RenderParagraph.text returns early. TextSpan.== and hashCode also ignore locale and spellOut. Separately, the metadata branch of RenderParagraph.text doesn't clear _cachedAttributedLabels, so even a metadata result would keep the old label.

Activity

  1. suryaKommana2662 commented on Nov 2, 2026

    @suryaKommana2662
    Contributor

    @ChandraChaan Thanks for the report. I was able to reproduce this issue locally using the provided test case. Routing to team-accessibility for further investigation.

    Logs

    ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
    The following TestFailure was thrown running a test:
    Expected: 'second'
      Actual: 'first'
       Which: is different.
              Expected: second
                Actual: first
                        ^
               Differ at offset 0
    
    When the exception was thrown, this was the stack:
    #4      main.<anonymous closure> (file:///Users/suryakommana/StudioProjects/default_app/test/widget_test.dart:13:5)
    <asynchronous suspension>
    #5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:192:15)
    <asynchronous suspension>
    #6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:2068:5)
    <asynchronous suspension>
    <asynchronous suspension>
    (elided one frame from package:stack_trace)
    
    This was caught by the test expectation on the following line:
      file:///Users/suryakommana/StudioProjects/default_app/test/widget_test.dart line 13
    The test description was:
      stale semantics label
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    00:01 +0 -1: stale semantics label [E]                                                                                                                                
      Test failed. See exception logs above.
      The test description was: stale semantics label
      
    
    To run this test again: /Users/suryakommana/develop/flutter/bin/cache/dart-sdk/bin/dart test /Users/suryakommana/StudioProjects/default_app/test/widget_test.dart -p vm --plain-name 'stale semantics label'
    00:01 +0 -1: Some tests failed.       

    Flutter Doctor Output

    [✓] Flutter (Channel master, 3.50.0-1.0.pre-340, on macOS 27.0 26A428 darwin-arm64, locale en-IN) [2.6s]
        • Flutter version 3.50.0-1.0.pre-340 on channel master at /Users/suryakommana/develop/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision ef74a07661 (3 hours ago), 2026-11-02 03:14:25 +0000
        • Engine revision ef74a07661
        • Dart version 3.15.0 (build 3.15.0-101.0.dev)
        • DevTools version 2.62.0-dev.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets,
          enable-record-use, enable-swift-package-manager, omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 36.0.0) [2.4s]
        • Android SDK at /Users/suryakommana/Library/Android/sdk
        • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
        • Platform android-37.0, build-tools 36.0.0
        • 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 25.0.2+-15348964-b329.117)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 27.2) [2.4s]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 27B52
        • CocoaPods version 1.17.0
    
    [✓] Chrome - develop for the web [4ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Connected device (2 available) [5.9s]
        • macOS (desktop) • macos  • darwin-arm64   • macOS 27.0 26A428 darwin-arm64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 156.0.8078.76
    
    [✓] Network resources [715ms]
        • All expected network resources are available.
    
    • No issues found!
  2. added
    a: tests"flutter test", flutter_test, or one of our tests
    a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    team-accessibilityOwned by Framework Accessibility team (i.e. responsible for accessibility code in flutter/flutter)
    and removed
    in triagePresently being triaged by the triage team
    on Nov 2, 2026
  3. added
    P2Important issues not at the top of the work list
    on Nov 4, 2026
  4. hannah-hyj commented on Nov 4, 2026

    @hannah-hyj
    Member

    From triage: Look like there is a draft PR for this issue already!

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 lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)a: tests"flutter test", flutter_test, or one of our testshas reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-accessibilityOwned by Framework Accessibility team (i.e. responsible for accessibility code in flutter/flutter)triaged-accessibilityTriaged by Framework Accessibility team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions