Repository navigation
fix(octane): keep trusted capture signal writes until the bubble handlers run - #1810
Merged
Merged
Conversation
…lers run 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]>
trueadm
marked this pull request as ready for review
October 6, 2026 11:48
Contributor
Benchmark report
Compares js-framework: 1k/10k row operationsAll 20 timed operations (20 without a verdict)
All 64 work counters are unchanged. Application bundle size (bytes)
9 other measured values are unchanged. Public-import reachability bundles (bytes)
36 other measured values are unchanged. |
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.
Summary
Fixes #1805. A signal write in a delegated
onXxxCapturehandler no longer reaches subscribers between the root's capture and bubble listeners of a browser-dispatched event. A form that reads the signal therefore keeps the user's edit: a range moved by keyboard, tap or drag takes the new value, and typed characters are no longer dropped.Why
The signal writes from one native event's delegated handlers publish together, when the root's bubble walk closes the event's batch. If a native listener stops propagation below the root, a fallback in
packages/octane/src/signals/native-read-events.tscloses the batch instead. Apart from checkbox/radiochange, that fallback was a microtask.The browser runs a microtask checkpoint after every listener of an event it dispatches itself. For a trusted keystroke, tap or drag, the fallback therefore ran right after the root's capture listener, before the target and bubble listeners. It published the capture write, a component reading the signal re-rendered, and the controlled
valuewas reasserted to the old state beforeonInputread the edit.#929 already fixed the same timing for the runtime's controlled-restore fallback (
finishCaptureDispatch), switching it to a task for trusted events. The batch lease says it mirrors that backstop, but it kept the older checkable-change test.Changes
native-read-events.ts: trusted events close the stopped-propagation fallback with a task. Script-dispatched events keep the microtask, because the dispatching script is still on the stack and the microtask cannot run before the bubble walk. The checkbox/radiochangetest is removed becauseisTrustedcovers it, as it does infinishCaptureDispatch.New real-browser regression,
packages/octane/tests/browser/signals-trusted-event-batch/(run by theoctane-signals-browserproject), in dev and prod builds. The fixture has the reporter's shape: a modulesignal$read in the component body, written by anonInputCaptureancestor. Four cases, all through Playwright's trusted input:A subscriber on the signal checks that the capture write publishes after the bubble
onInput.Same fixture with
useStateinstead of a signal write: React 19.2.7 also re-renders between the capture and bubble listeners, through its sync-lane microtask, and resets the range. Octane matches React there, so this PR leaves that path alone. Only the signal batch promises to cover the whole event.Validation
pnpm format:check(scopedpnpm format:files:checkon the changed files passes)pnpm typecheck(scopedpnpm typecheck:fileson the source, test and.tsrxfixture passes)pnpm test(left to CI because of local machine load)vitest run --project octane-signals-browser packages/octane/tests/browser/signals-trusted-event-batch. Before the fix: 8/8 fail. The range stays at1after ArrowRight and after a click at the right end, typed text stays empty, and the stopped-propagation listener sees the reset value. After the fix: 8/8 pass, including after rebasing on fix(octane): project a hydrated form control's client value like React 19 #1808.pnpm syncproduces no changes.Risk / follow-ups
setTimeout(0)instead ofqueueMicrotask. It is scheduled only for trusted bubbling events whose type has both capture and bubble delegation, in an app that loads the signals engine. A capture-only type closes its batch synchronously. In the normal case, the bubble walk closes the batch first and the timer callback returns immediately.changealready worked this way. Writes in that window are published when the task runs, not lost.benchmarks/bundle-size/minimal-gates.mjsdocuments for perf(compiler): shrink plain-module hook boundaries and inline memo lowering #1634. No budget changes.Provenance
agent-authored)🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Note
Medium Risk
Changes native event batch timing for trusted bubbling events (microtask → task fallback), affecting when signal writes publish during user input; mitigated by alignment with existing controlled-restore behavior and browser tests.
Overview
Fixes controlled inputs losing edits when an ancestor
onXxxCapturewrites a signal the form reads in render. Signal batches for delegated native events were closing their stopped-propagation fallback viaqueueMicrotask, which runs after the root capture listener on browser-dispatched (trusted) events—before target/bubbleonInput—so subscribers re-rendered and reasserted the oldvalue.endNativeEventBatchinnative-read-events.tsnow schedules that fallback withsetTimeout(0)forevent.isTrusted, matchingfinishCaptureDispatch, and drops the checkbox/radiochangespecial case. Script-dispatched events still use a microtask.Adds Playwright regression coverage (
signals-trusted-event-batch) in dev and prod: capture signal write + controlled range/text, plus propagation stopped below the root.Reviewed by Cursor Bugbot for commit b6f7597. Bugbot is set up for automated code reviews on this repo. Configure here.