[web] With semantics enabled, a TextField reports no composing range during IME composition

Open Beginner friendly
#197,796 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
83/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
dart, flutter

Research direction

Start in engine/src/flutter/lib/web_ui/lib/src/engine/semantics/text_field.dart, especially SemanticsTextEditingStrategy.addEventHandlers, and compare its event setup with the default, iOS, Android, and Firefox strategies in engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart. Check the existing composition tests and add coverage for IME composition with semantics enabled. Done when the composing range is preserved during composition and clears on commit.

Written by the indexing model from the issue text.

Description

Steps to reproduce

My app calls ensureSemantics() at startup for every visitor, and its chat input doesn't send on Enter while value.composing is set. With semantics on, on 3.47.6, the Return that confirms a Japanese conversion sent the unconfirmed text. Unlike #193846, semantics are on before the field is focused, and the text composes correctly. Only the range is lost.

  1. flutter create bug, replace lib/main.dart with the code sample, and run flutter run -d chrome.
  2. Click the field, switch to a Japanese input source, and type a few characters without pressing Return.
  3. Read the composing: line under the field.
  4. Add ?semantics=on to the URL, reload, and repeat steps 2 and 3.

Tested: 3.50.1 stable in Chrome 158 on macOS 26.5.1, typing with the macOS Japanese input source, both by these steps and in a release build. Injecting the composition with the DevTools Protocol's Input.imeSetComposition reproduced it in release --wasm, on master cab71e9f, and on 3.47.6 with material.dart. Safari and Firefox not run.

Expected results

In both runs composing covers the unconfirmed characters and the field underlines them. TextEditingValue.composing is "the range of text that is still being composed".

Actual results

Without semantics: composing: 0, 5, with the text underlined.

With ?semantics=on: composing: -1, -1 after every keystroke, and no underline.

Cause

SemanticsTextEditingStrategy.addEventHandlers never calls addCompositionEventHandlers, which the default, iOS, Android and Firefox strategies all call. So composingText stays null and determineCompositionState adds no range. flutter/engine#33590 added those four calls in 2022, fixing #65357.

Patching that call into a 3.50.1 profile build's main.dart.js fixed it. With semantics on, the range then covered the composing text and cleared on commit, as without semantics. I can send this as a PR if the approach is right.

Code sample
Code sample
import 'package:material_ui/material_ui.dart';
import 'package:flutter/semantics.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  // Open the page with ?semantics=on to turn semantics on before the field
  // takes focus.
  if (Uri.base.queryParameters['semantics'] == 'on') {
    SemanticsBinding.instance.ensureSemantics();
  }
  runApp(const MaterialApp(home: Scaffold(body: Repro())));
}

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

  @override
  State<Repro> createState() => _ReproState();
}

class _ReproState extends State<Repro> {
  final controller = TextEditingController();

  @override
  void initState() {
    super.initState();
    controller.addListener(() {
      final value = controller.value;
      debugPrint(
        '"${value.text}" composing: ${value.composing.start}, ${value.composing.end}',
      );
    });
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) => Padding(
    padding: const EdgeInsets.all(16),
    child: Column(
      children: [
        TextField(controller: controller, autofocus: true),
        ValueListenableBuilder<TextEditingValue>(
          valueListenable: controller,
          builder: (context, value, _) => Text(
            'composing: ${value.composing.start}, ${value.composing.end}',
          ),
        ),
      ],
    ),
  );
}
Screenshots or Video

No response

Logs
Logs
Launching lib/main.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome...             11.4s

Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).

This app is linked to the debug service: ws://127.0.0.1:49541/9-Zs0yRu4Zo=/ws
Debug service listening on ws://127.0.0.1:49541/9-Zs0yRu4Zo=/ws
A Dart VM Service on Chrome is available at: http://127.0.0.1:49541/9-Zs0yRu4Zo=
The Flutter DevTools debugger and profiler on Chrome is available at: http://127.0.0.1:49541/9-Zs0yRu4Zo=/devtools/?uri=ws://127.0.0.1:49541/9-Zs0yRu4Zo=/ws
Starting application from main method in: org-dartlang-app:///web_entrypoint.dart.
"" composing: -1, -1
"み" composing: 0, 1
"ミニ" composing: 0, 2
"みにく" composing: 0, 3
"ミニくら" composing: 0, 4
"ミニくらみ" composing: 0, 5
"ミニくらみ" composing: -1, -1
"ミニくらみ" composing: 0, 5
"ミニくらみ" composing: -1, -1
"ミニくらみ" composing: 0, 5
DDC is about to load 1/2 scripts with pool size = 1000
DDC is about to load 1031/1031 scripts with pool size = 1000
Starting application from main method in: org-dartlang-app:///web_entrypoint.dart.
"" composing: -1, -1
"み" composing: -1, -1
"ミニ" composing: -1, -1
"みにく" composing: -1, -1
"ミニくら" composing: -1, -1
"ミニくらみ" composing: -1, -1
Flutter Doctor output
Doctor output
[✓] Flutter (Channel stable, 3.50.1, on macOS 26.5.1 25F80 darwin-arm64, locale ja-US) [450ms]
    • Flutter version 3.50.1 on channel stable at <redacted>/fvm/versions/3.50.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ae9b586f34 (2 weeks ago), 2026-11-18 17:01:07 -0800
    • Engine revision 4d35714800
    • Dart version 3.14.0
    • 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

[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [1,591ms]
    • Android SDK at <redacted>/Library/Android/sdk
    • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
    • Platform android-36.1, build-tools 36.1.0
    • Java binary at: /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment Homebrew (build 21.0.13.0.2)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 26.3) [1,260ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 17C529
    • CocoaPods version 1.16.2

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

[✓] Connected device (4 available) [11.4s]
    • Pixel 7 Pro (mobile)         • <redacted>            • android-arm64  • Android 17 (API 37)
    • <redacted> (mobile) • <redacted> • ios            • iOS 27.0.1 24A446
    • macOS (desktop)              • macos                     • darwin-arm64   • macOS 26.5.1 25F80 darwin-arm64
    • Chrome (web)                 • chrome                    • web-javascript • Google Chrome 158.0.8127.91

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

• No issues found!
Dominant language
Dart
Stars
182k
Forks
32k
Avg merge
1d 21h
Merged PRs (30d)
336

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from flutter/flutter

All issues in flutter/flutter

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.