Skip to content

fix: close the delegated capture window after trusted propagation ends - #929

Merged
trueadm merged 1 commit into
mainfrom
claude/frosty-curran-9ceaf6
Sep 2, 2026
Merged

trueadm merged 1 commit into
mainfrom
claude/frosty-curran-9ceaf6

Conversation

@trueadm

@trueadm trueadm commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • node benchmarks/controlled-form/run.mjs octane-tsrx 8 timed out on main at the typing check (input[data-field-index="37"] never reached octane benchmaXrk). The weekly bench workflow has shown the same failure on Linux since 2026-08-17 (it passed on 2026-08-10). The React target passes on the same Playwright/Chromium, so keyboard delivery was not the problem: every keystroke into the controlled input was being reverted before onInput ran.
  • Root cause in finishCaptureDispatch: when any onXxxCapture handler for an event type is registered, the root's capture-phase listener queues a microtask fallback that closes the capture segment's controlled-restore window in case a native listener stops the bubble below the root. Browsers run a microtask checkpoint after every listener of an event they dispatch themselves, so for a trusted event that fallback fired between the root's capture listener and its bubble listener, snapped the controlled value back to the last rendered value, and onInput then read the old value (an Object.is-equal update, so no render). The benchmark fixture's onInputCapture (added by perf: finish delegated-event and marker optimizations #704) exposed the latent bug.
  • Fix: trusted events close the window with a task, after native propagation has finished; script-dispatched events keep the microtask fallback, which cannot run before the dispatching script yields. The old checkable-change special case was the same bug misdiagnosed as checkbox-specific and is subsumed.

Changes

  • packages/octane/src/runtime.ts: finishCaptureDispatch picks the fallback scheduling from event.isTrusted.
  • benchmarks/news/runtime-stress.mjs: the controlled-form typing wait now reports the input value, output text, focus, selection, input identity, field renders, validation requests, and any browser errors when it times out, so failures are diagnosable. The correctness check itself is unchanged.
  • packages/octane/tests/browser/event-boundaries/* + tests/_fixtures/event-commit-timing.tsrx: real-browser regression. Octane and React type trusted keystrokes into a controlled input under an onInputCapture ancestor with an outside native listener on the input; both must commit the edit and the outside listener must observe the typed text. A second case pins Octane's revert of an edit whose bubble segment a native listener stopped, and that the revert happens only after propagation (marked as an Octane divergence: React never restores in that case). jsdom cannot cover this because dispatchEvent never checkpoints between listeners.
  • .changeset/trusted-capture-fallback-task.md: patch for octane.

Validation

  • pnpm format:check (repo-wide, passes)
  • pnpm typecheck (repo-wide, passes)
  • pnpm test (not run in full; see below)
  • targeted tests: vitest projects octane + octane-prod (894 files, 15455 tests pass); octane-events-browser for event-boundaries, native-change, mobile-input, continuous-actions (68 tests pass)
  • node benchmarks/controlled-form/run.mjs octane-tsrx 8: PASS, 8 correctness-gated samples (typing, caret, focus, controls, submit, stale validation, reset). react 1 also passes as a control.
  • Pre-fix check with the old runtime restored: the new Octane test fails (the outside listener records native:target: instead of native:target:a) while the React case passes, and the harness now reports:
FAIL controlled-form/octane-tsrx: Error: octane-tsrx: controlled typing did not converge on "octane benchmaXrk": {"value":"","output":"","focused":true,"inputSame":true,"selectionStart":0,"selectionEnd":0,"fieldRenders":1,"validationRequests":17}
  • pnpm sync produced no generated changes.

Risk / follow-ups

  • Trusted events that a script dispatches synchronously (requestSubmit(), activation-fired input/change inside click()) now restore a stopped edit one task later than before; still after propagation, and React never restores in that case at all.
  • The weekly bench workflow also has unrelated failures in other suites (a ripple identity gate, a preact suite), so it stays red until those are handled.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Touches core delegated event timing for all trusted discrete events; trusted script-dispatched edits may restore one task later than before, though still after propagation.

Overview
Fixes controlled inputs reverting on every keystroke when any onXxxCapture handler is registered for that event type. The delegated capture “stopped propagation” fallback was scheduled as a microtask, which browsers can run between the root’s capture and bubble listeners on trusted events—restoring the rendered value before onInput runs.

finishCaptureDispatch now schedules that fallback with setTimeout(0) for trusted events (after full native propagation) and keeps queueMicrotask for script-dispatched events, replacing the old checkbox-only change special case.

Adds browser regression coverage (Octane vs React) for typing into a controlled field under onInputCapture, plus richer controlled-form benchmark timeout diagnostics. Patch changeset for octane.

Reviewed by Cursor Bugbot for commit 905084b. Bugbot is set up for automated code reviews on this repo. Configure here.

The root capture listener queued a microtask to close the capture
segment's controlled-restore window when a native listener stops the
bubble below the root. Browsers run a microtask checkpoint after every
listener of an event they dispatch themselves, so for a trusted event the
fallback fired between the root's capture and bubble listeners, restored
the controlled value before onInput ran, and lost every keystroke once any
onXxxCapture handler for that type was registered anywhere in the app.
Trusted events now close the window with a task; script-dispatched events
keep the microtask fallback.

Also make the controlled-form benchmark report the field state when the
typing check times out, and add a real-browser regression comparing
Octane and React typing through an onInputCapture ancestor.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Sep 2, 2026
@github-actions
github-actions Bot marked this pull request as draft September 2, 2026 12:07
@trueadm
trueadm marked this pull request as ready for review September 2, 2026 12:15
@trueadm
trueadm merged commit 6a6dbc1 into main Sep 2, 2026
59 checks passed
@trueadm
trueadm deleted the claude/frosty-curran-9ceaf6 branch September 2, 2026 13:09
trueadm added a commit that referenced this pull request Oct 6, 2026
…lers run (#1810)

A signal write in a delegated onXxxCapture handler belongs to the native
event's signal batch, which the root's bubble walk closes. When a native
listener stops propagation below the root, a fallback closes the batch
instead. That fallback was a microtask for every event except checkbox and
radio change. The browser checkpoints microtasks after every listener of an
event it dispatches itself, so for a keystroke, tap or drag the fallback
published the capture write between the root's capture and bubble
listeners. A component reading the signal re-rendered and reasserted its
controlled value before onInput could read the edit: ranges stayed put and
typed characters were dropped.

#929 already moved the runtime's controlled-restore fallback
(finishCaptureDispatch) to a task for trusted events; the batch lease that
mirrors it kept the older checkable-change test. Trusted events now close
the batch with a task, which also covers the checkable change case, and
script-dispatched events keep the microtask.

Fixes #1805

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant