[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.
This commit is contained in:
zhongliugo 2026-01-29 08:15:43 -08:00 committed by GitHub
parent f363764d92
commit fc6d13a1b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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();
}
}