Skip to content

[Web] With semantics enabled, a focused TextField loses its text when its semantics node is merged into a new one #195290

Open

Description

@nogringo

Steps to reproduce

  1. Run the sample below with flutter run -d chrome.
  2. The field has the focus. Type abc within 5 seconds.
  3. After 5 seconds, type d.

The sample calls SemanticsBinding.instance.ensureSemantics(). Without that line, everything works. An app without it gets the same bug as soon as a user activates Flutter web's hidden "Enable accessibility" button.

Expected results

The field shows abcd.

Actual results

The field shows d. The text typed before the semantics change is erased, and onChanged reports an empty string before the d. The field keeps the focus.

The sample turns on a Semantics(container: true) above the field after 5 seconds, which merges the field's semantics into a new node.

What I think happens: the field now belongs to a new semantics node, so the engine creates a new SemanticTextField with an empty <input>. Once the editing strategy uses that element, it reads its empty value and sends it to the framework as the editing state, which replaces the controller's text.

Code sample

Code sample
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/semantics.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SemanticsBinding.instance.ensureSemantics();
  runApp(
    const MaterialApp(
      home: Scaffold(
        body: Padding(padding: EdgeInsets.all(24), child: Sample()),
      ),
    ),
  );
}

class Sample extends StatefulWidget {
  const Sample({super.key});

  @override
  State<Sample> createState() => _SampleState();
}

class _SampleState extends State<Sample> {
  bool _container = false;

  @override
  void initState() {
    super.initState();
    // Merges the field's semantics into a new container node.
    Timer(const Duration(seconds: 5), () => setState(() => _container = true));
  }

  @override
  Widget build(BuildContext context) {
    return Semantics(
      container: _container,
      child: const TextField(
        autofocus: true,
        decoration: InputDecoration(hintText: 'Type a few characters'),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

No response

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.47.7, on macOS 27.0.1 26A434 darwin-arm64, locale en-US)
    • Flutter version 3.47.7 on channel stable at /Users/gringo/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision abaf9c5237 (2 weeks ago), 2026-10-08 09:51:21 -0700
    • Engine revision deb287481e
    • Dart version 3.13.5
    • DevTools version 2.60.0

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

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 27.0.1 26A434 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 155.0.8059.85

Activity

  1. added
    in triage
    on Oct 26, 2026
  2. suryaKommana2662 commented on Oct 26, 2026

    @suryaKommana2662
    Contributor

    @nogringo I was able to reproduce the issue on Flutter Web using Chrome on Flutter 3.47.7 stable. After entering abc, the text field was cleared when the semantics node changed after 5 seconds. Typing d afterward displayed only d instead of abcd. Routing this to the team-accessibility for further investigation.

    Flutter Doctor Output

    [✓] Flutter (Channel master, 3.50.0-1.0.pre-209, on macOS 27.0 26A428 darwin-arm64, locale en-IN) [1,218ms]
        • Flutter version 3.50.0-1.0.pre-209 on channel master at /Users/suryakommana/develop/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 7b0a985e54 (4 days ago), 2026-10-23 00:20:16 +0000
        • Engine revision 7b0a985e54
        • Dart version 3.15.0 (build 3.15.0-67.0.dev)
        • DevTools version 2.61.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) [1,429ms]
        • 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.1) [770ms]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 27A9275
        • CocoaPods version 1.17.0
    
    [✓] Chrome - develop for the web [4ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Connected device (4 available) [5.9s]
        • iPhone 18 Pro (mobile)                • D80F2104-E911-4251-BEDD-E67D9B7EBF58 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-27-0 (simulator)
        • iPad Pro 13-inch (M5) (16GB) (mobile) • 818164C9-D191-4401-BDB3-24008DE30CEF • ios            • com.apple.CoreSimulator.SimRuntime.iOS-27-0 (simulator)
        • macOS (desktop)                       • macos                                • darwin-arm64   • macOS 27.0 26A428 darwin-arm64
        • Chrome (web)                          • chrome                               • web-javascript • Google Chrome 155.0.8059.85
    
    [✓] Network resources [502ms]
        • All expected network resources are available.
    
    • No issues found!
  3. added
    a: accessibility
    has reproducible steps
    fyi-web
    team-accessibility
    a: text input
    and removed
    in triage
    on Oct 26, 2026
  4. flutter-zl commented on Oct 28, 2026

    @flutter-zl
    Contributor
    Reproduced on Chrome with a recent master build.
    
    Demo: https://flutter-demo-87-before.web.app
    
    1. Click "Start". The field gets focus and a 5 second countdown starts.
    2. Type `abc` before the countdown ends.
    3. After the countdown, type `d`.
    
    The text is erased the moment the container turns on, before the next key. The field keeps focus, and `onChanged` reports `""` and then `"d"`:
    
    ```
    typed abc      controller.text: "abc"   onChanged: "a", "ab", "abc"
    container on   controller.text: ""
    typed d        controller.text: "d"     onChanged: "a", "ab", "abc", "", "d"
    ```
    
    This looks like the same root cause as #194636: the re-created semantics `<input>` comes back empty and its value is sent to the framework as an edit. #195141 addresses that path; I will check whether
    it also fixes this case.
    
  5. added
    triaged-web
    P2
    P1
    and removed
    P2
    on Oct 28, 2026
  6. self-assigned this
    on Oct 28, 2026
  7. removed
    fyi-web
    triaged-web
    on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1a: accessibilitya: text inputhas reproducible stepsteam-accessibility

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions