Skip to content

fix: clear stale input state after form reset - #1360

Open
Bembaby wants to merge 2 commits into
testing-library:mainfrom
Bembaby:codex/fix-native-form-reset-1359
Open

Bembaby wants to merge 2 commits into
testing-library:mainfrom
Bembaby:codex/fix-native-form-reset-1359

Conversation

@Bembaby

@Bembaby Bembaby commented Nov 30, 2026 •

Copy link
Copy Markdown

What

Fixes #1359. After a native form reset, typing into the same input or textarea starts from the value and selection left by the DOM.

Why

Typing one, clicking a submit button whose handler prevents submission and calls form.reset(), and then typing two yields onetwo on the base. The reset clears the DOM value, but the browser does not call the JavaScript value setter, so user-event's cached value and selection survive.

How

Observe native reset events in the tree containing prepared controls. Record the reset for the form's associated inputs and textareas, including controls outside the form element. On the next state access after dispatch, clear the cached value, selection, and blur change baseline if the reset completed without cancellation. The DOM supplies the default value and selection. Clearing the cache dispatches no input or change events.

The regression tests cover the submit handler, direct reset, reset button, empty and nonempty defaults, textarea, repeated cycles, cancellation, selection, external controls, unrelated forms, and an open shadow root. This is a patch-level behavior correction with no public API changes.

Validation

  • The submit/reset/type regression failed on b20f4096d57d9539a0307087bb80569bf57b345a with onetwo and passed with two. The standalone sequence also reproduced with user-event 14.6.13, Node 26.13.1, and jsdom 31.0.1, and passed with the patched source. On Ubuntu, the built CJS entry reproduced on the base and passed with the patch using Node 22.22.1 and jsdom 20.0.3.
  • Windows, Node 24.15.0 and npm 11.12.1. npm run setup -s, npm run lint, and npm run validate passed. Lint reported the same 66 warnings as the base. CI=true npm run test -- --coverage --runInBand passed 586 tests in 55 suites and all 79 snapshots.
  • Ubuntu under WSL, Node 22.22.1, npm 9.2.0, and Yarn 1.22.22 for dependency installation. npm run setup:env and npm run build passed. The Windows build hit the same ESM drive-letter URL error on both the patch and the base.
  • CI=true npm run test:toolbox completed all 165 suite runs with zero skipped tests, timeouts, or runner errors. All seven new tests passed in every environment. The patch and the clean base reported the same 18 pre-existing failures, also visible in the upstream CI run for the base.
Toolbox environment Patched pass Base pass Failures on each
jsdom 20.0.3, DOM Testing Library 10.4.2, React 18.3.1 584 577 2
jsdom 20.0.3, DOM Testing Library 8.20.1, React 17.0.2 579 572 7
Chrome for Testing 151.0.7922.34, DOM Testing Library 10.4.2, React 18.3.1 577 570 9

GitHub Actions validation passed on the initial commit. The run for e611b6f is awaiting maintainer approval, with zero jobs started. Latest PR CI run

Checklist

  • Documentation (N/A for this bug fix)
  • Tests
  • Ready to be merged after maintainer review and CI

This change and PR description were prepared with Codex assistance.

Comment thread src/document/UI.ts Outdated
pendingResets.set(element, event)
}

function completeUIReset(element: HTMLInputElement | HTMLTextAreaElement) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this "finish UI Reset"? as opposed to complete which might be interpreted as everything

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, finishUIReset is clearer. I renamed the helper and all six call sites in e611b6f. Prettier, lint, type checking, and all 586 Jest tests passed. The toolbox reported the same 18 existing failures.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

user.type() keeps the old value after form.reset()

2 participants