From fc6d13a1b2d365083f6aae715629df982c5bc8f8 Mon Sep 17 00:00:00 2001 From: zhongliugo Date: Thu, 29 Jan 2026 08:15:43 -0800 Subject: [PATCH] [web] Use defensive null check in text editing placeElement (#180795) Fixes #178619 Uses defensive null check (?.) instead of null assertion (!) when calling focusWithoutScroll() on focusedFormElement in GloballyPositionedTextEditingStrategy.placeElement(). This prevents a crash that can occur due to a race condition where hasAutofillGroup returns true but focusedFormElement is null by the time it's accessed. --- .../web_ui/lib/src/engine/text_editing/text_editing.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart index 5d07a5db843..21c3f7bb831 100644 --- a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart +++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart @@ -1176,7 +1176,11 @@ class GloballyPositionedTextEditingStrategy extends DefaultTextEditingStrategy { // only after placing it to the correct position. Hence autofill menu // does not appear on top-left of the page. // Refocus on the elements after applying the geometry. - focusedFormElement!.focusWithoutScroll(); + // placeForm() involves DOM manipulation which can trigger synchronous + // events (like blur). These events might invalidate the current + // inputConfiguration or disable the strategy before placeForm() returns. + // Therefore, we must defensively check if the element is still valid/present. + focusedFormElement?.focusWithoutScroll(); moveFocusToActiveDomElement(); } }