Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When automating React controlled inputs,
clearInput()andclearInputByDeleting()silently fail to notify React, leaving the component state stale. The real-world consequence is a mixed value when re-filling a pre-filled input — e.g. old value"10", new value"25", actual result"025"or"1025".Root cause
React installs an instance-level
valueproperty setter on controlled inputs (its_valueTrackermechanism). Directel.value = xassignments in JavaScript go through this setter, updating both the DOM value and the tracker's "last known value" simultaneously. When aninputevent then fires, React comparesel.value === tracker.getValue()— they match — so React concludes nothing changed and never callsonChange. The clear appears to work at the DOM level but React silently reverts it on the next render cycle.Both methods were affected:
clearInput()usedelement.value = ""with no event dispatch at all — a double failureclearInputByDeleting()usedel.value = el.value.slice(1)on each iteration, which also went through the tracker setter and then fired aninputevent that React ignoredFix
clearInput()— replaced the direct.valueassignment with a call to the native prototype setter (Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set.call(el, '')), which bypasses the tracker entirely. Added anInputEventdispatch so React detects the mismatch and firesonChange.clearInputByDeleting()— removed the JS value mutation (el.value = el.value.slice(1)) and the manual event dispatch entirely. The CDPdispatchKeyEventwithkey="Delete"at cursor position 0 already uses the browser's native text-editing pipeline, which bypasses the tracker and correctly triggers React's change detection. The JS snippet now only readsel.value.lengthto check the remaining character count.Tests
Added
ReactControlledInputTestwith an accompanying HTML fixture that faithfully reproduces the_valueTrackermechanism in vanilla JS — same instance-level setter, same mismatch comparison, same state tracking.testClearInputDoesNotNotifyReactclearInput()leaves React state at"10"instead of""testClearInputByDeletingDoesNotNotifyReactclearInputByDeleting()leaves React state at"0"instead of""testFillReactControlledInputProducesMixedValue"025"instead of"25"All three tests failed before the fix and pass after. The existing
ElementTest.testInput(plain HTML input) continues to pass, confirming no regression for non-React inputs.