Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Description
Port of cdpdriver/kdriver#61 and cdpdriver/kdriver#62 to zendriver.
Problem
When automating React controlled inputs,
clear_input()andclear_input_by_deleting()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). Directn.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.Both methods were affected:
clear_input()usedelement.value = ""with no event dispatch at all — a double failureclear_input_by_deleting()usedn.value = n.value.slice(1)on each iteration, which also went through the tracker setter; the subsequentinputevent was silently ignored by ReactA secondary bug in
clear_input_by_deleting: the loop usedDelete(keyCode 46) with the cursor at position 0. On some VM environments,VK_DELETEis treated as backward-delete, making it a no-op at position 0 and causing an infinite loop.Fix
clear_input()— 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.clear_input_by_deleting()— switched fromDeleteat position 0 toBackspace(keyCode 8) with the cursor explicitly kept at the end of the remaining text, which is unambiguous on every platform. Replaced the directn.value = n.value.slice(1)mutation with a native prototype setter call, and added anInputEventdispatch after each deletion so React correctly firesonChangeon every character removed.Tests
Added
tests/core/test_react_controlled_input.pywith an accompanying HTML fixture (tests/sample_data/react-controlled-input-test.html) that faithfully reproduces the_valueTrackermechanism in vanilla JS — same instance-level setter, same mismatch comparison, same state tracking. Three tests, each run in both headless and headful mode:test_clear_input_does_not_notify_reactclear_input()leaves React state at"10"instead of""test_clear_input_by_deleting_does_not_notify_reactclear_input_by_deleting()leaves React state at a partial value instead of""test_fill_react_controlled_input_produces_mixed_value"025"or"1025"instead of"25"Pre-merge Checklist
./scripts/format.shand./scripts/lint.shscripts. My code is properly formatted and has no linting errors.uv run pytestand ensured all tests pass.[Unreleased]section.