fix: accept values written into the login fields by a password manager #2
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/password-manager-autofill"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Extensions fill a field by assigning
element.valueand then dispatchinginput/change. React installs its ownvaluedescriptor on theelement, so that assignment also updates React's internal value tracker;
when the event arrives React compares old and new, sees no difference,
and suppresses the synthetic
onChange. react-hook-form never learnsthe field was filled,
formState.isValidstays false, the submit buttonstays disabled, and
handleSubmitwould send an empty value.The user sees both fields visibly filled, cannot submit, and retypes
username and password by hand -- on both steps of the flow.
Measured against the live login UI with a headless browser:
plain
el.value = x+ events (what an extension does) -> stays disablednative prototype setter + input event -> enables
plain assignment fired before hydration -> stays disabled
useAutofillSync attaches a native
input/changelistener, which sitsbelow React's synthetic layer and fires regardless, and pushes the DOM
value into the form itself. It also reads the field once on mount, which
covers fill-on-page-load: those writes land before hydration, so no
event ever reaches a React listener.
This does not collapse the two-step flow -- a password manager still
acts once per page -- but fill-on-page-load now works unattended on both.
Co-Authored-By: Claude Opus 5 noreply@anthropic.com