Repository navigation
[web] Keep live autofill form across TextInput.updateConfig - #194015
flutter-zl wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors EngineAutofillForm by extracting form adoption logic into a private _adopt method and updates TextInputUpdateConfig.run to reuse the live form when configuration updates occur with the same form identifier. It also adds regression tests to verify that fields remain editable and forms are correctly managed during updates. The review feedback suggests removing a redundant null assertion operator (!) on liveForm in TextInputUpdateConfig.run because it is already promoted to a non-nullable type.
| // blur cannot put it to sleep and the next placement builds a second form. | ||
| if (liveForm?.formElement != null && | ||
| newForm != null && | ||
| newForm.formIdentifier == liveForm!.formIdentifier) { |
There was a problem hiding this comment.
Since liveForm is a local final variable and we have already checked liveForm?.formElement != null in the condition, liveForm is promoted to a non-nullable type by Dart's flow analysis. The null assertion operator (!) is redundant here and can be safely removed.
| newForm.formIdentifier == liveForm!.formIdentifier) { | |
| newForm.formIdentifier == liveForm.formIdentifier) { |
There was a problem hiding this comment.
We need to keep the !. Checking liveForm?.formElement != null does not tell Dart that liveForm itself is not null. Without the !, the code does not compile.
Fixes #192544
Fixes #192102
Problem
On web, a focused autofill TextField that receives
TextInput.updateConfig, for example from an obscureText toggle, stops accepting input for good. The engine swaps in a newEngineAutofillFormthat was never woken up, so on blurdisable()removes the editing element instead of keeping the form dormant, and later sessions swap the new element into a node that is no longer in the DOM. The same mismatch makes the next geometry update build a second form, which can end in the null check crash reported in the comments.Fix
TextInputUpdateConfignow hands the live form's DOM and per-field tracking to the new form when both have the sameformIdentifier, reusing the adoption logicwakeUp()already had. Field values and attributes from the update still apply. An update that changes the set of fields keeps the old behavior.Demo
Before: https://flutter-demo-74-before.web.app
After: https://flutter-demo-74-after.web.app
Wait about 4 seconds for the scripted focus steps to finish, then click Field A and type. Before: Field A shows a caret but accepts no input. After: Field A accepts input.