Skip to content

fix(octane): keep trusted capture signal writes until the bubble handlers run - #1810

Merged
trueadm merged 1 commit into
mainfrom
fix/trusted-capture-signal-lease
Oct 6, 2026
Merged

trueadm merged 1 commit into
mainfrom
fix/trusted-capture-signal-lease

Conversation

@trueadm

@trueadm trueadm commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #1805. A signal write in a delegated onXxxCapture handler 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.ts closes the batch instead. Apart from checkbox/radio change, 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 value was reasserted to the old state before onInput read 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/radio change test is removed because isTrusted covers it, as it does in finishCaptureDispatch.

  • New real-browser regression, packages/octane/tests/browser/signals-trusted-event-batch/ (run by the octane-signals-browser project), in dev and prod builds. The fixture has the reporter's shape: a module signal$ read in the component body, written by an onInputCapture ancestor. Four cases, all through Playwright's trusted input:

    • keyboard edits on a controlled range;
    • a pointer click on the range;
    • typing into a controlled text input;
    • a native target listener that stops propagation. It must see the browser's value before the capture write publishes, and the write must still publish once dispatch finishes.

    A subscriber on the signal checks that the capture write publishes after the bubble onInput.

Same fixture with useState instead 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 (scoped pnpm format:files:check on the changed files passes)
  • pnpm typecheck (scoped pnpm typecheck:files on the source, test and .tsrx fixture passes)
  • pnpm test (left to CI because of local machine load)
  • targeted tests: vitest run --project octane-signals-browser packages/octane/tests/browser/signals-trusted-event-batch. Before the fix: 8/8 fail. The range stays at 1 after 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 sync produces no changes.

Risk / follow-ups

  • Per-event cost: the fallback now goes through setTimeout(0) instead of queueMicrotask. 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.
  • When propagation is stopped below the root, the global signal batch now stays open until the next task rather than the next microtask checkpoint. Checkbox/radio change already worked this way. Writes in that window are published when the task runs, not lost.
  • Bundle size: the bench report shows raw −82 B and gzip −16 to −32 B on every row. Brotli rises by 1–114 B, inside its 256 B headroom, from the same non-monotonic effect benchmarks/bundle-size/minimal-gates.mjs documents for perf(compiler): shrink plain-module hook boundaries and inline memo lowering #1634. No budget changes.

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
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 onXxxCapture writes a signal the form reads in render. Signal batches for delegated native events were closing their stopped-propagation fallback via queueMicrotask, which runs after the root capture listener on browser-dispatched (trusted) events—before target/bubble onInput—so subscribers re-rendered and reasserted the old value.

endNativeEventBatch in native-read-events.ts now schedules that fallback with setTimeout(0) for event.isTrusted, matching finishCaptureDispatch, and drops the checkbox/radio change special 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.

…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
trueadm marked this pull request as ready for review October 6, 2026 11:48
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent fix PR: bug fix labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

  • 🔴 bundle-size: 11 value(s) increased within budget
  • 🔴 bundle-reachability: 7 value(s) increased within budget

Compares b353f5490, the merge commit's first parent with 34c82a0a3 on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.042 3.183 +3.3% −3.1% … +8.2% ⚪ within noise
octane-tsrx replace 6.917 7.558 ±0.0% −1.4% … +2.1% ⚪ within noise
octane-tsrx add 2.675 2.767 −0.0% −3.8% … ±0.0% ⚪ within noise
octane-tsrx update 0.135 0.134 −1.2% −2.2% … +1.7% ⚪ within noise
octane-tsrx select 0.006 0.006 +0.3% −0.5% … +1.6% ⚪ within noise
octane-tsrx swap 0.038 0.040 +3.7% +1.9% … +5.3% ⚪ within noise
octane-tsrx remove 0.017 0.018 +0.7% −1.5% … +1.9% ⚪ within noise
octane-tsrx runlots 29.758 29.858 +0.0% −3.2% … +3.3% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 +0.7% −0.7% … +1.5% ⚪ within noise
octane-tsrx clear 34.250 36.067 +5.6% +2.1% … +8.8% ⚪ within noise
octane-jsx run 3.850 3.717 −2.6% −2.8% … ±0.0% ⚪ within noise
octane-jsx replace 6.533 6.967 ±0.0% −1.6% … +3.7% ⚪ within noise
octane-jsx add 3.275 3.308 +2.9% −1.3% … +4.2% ⚪ within noise
octane-jsx update 0.314 0.298 −3.9% −7.8% … −1.4% ⚪ within noise
octane-jsx select 0.189 0.189 −2.9% −6.3% … +1.3% ⚪ within noise
octane-jsx swap 0.248 0.263 −0.0% −4.5% … +4.5% ⚪ within noise
octane-jsx remove 0.176 0.177 +1.1% −0.6% … +1.9% ⚪ within noise
octane-jsx runlots 32.542 32.050 −0.6% −3.6% … +2.0% ⚪ within noise
octane-jsx select_lots 1.986 1.926 +3.0% −0.4% … +5.9% ⚪ within noise
octane-jsx clear 40.367 41.775 +1.4% −1.1% … +5.9% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

target metric base head Δ
octane-tsrx js_raw 111,282 111,200 −82 (−0.1%) 🟢
octane-tsrx js_gzip 36,232 36,200 −32 (−0.1%) 🟢
octane-tsrx js_brotli 32,156 32,065 −91 (−0.3%) 🟢
octane-tsrx app_gzip 2,335 2,334 −1 (−0.0%) 🟢
octane-tsrx app_brotli 2,033 2,031 −2 (−0.1%) 🟢
octane-tsrx fw_raw 104,336 104,254 −82 (−0.1%) 🟢
octane-tsrx fw_gzip 33,897 33,866 −31 (−0.1%) 🟢
octane-tsrx fw_brotli 30,123 30,034 −89 (−0.3%) 🟢
octane-tsrx todo_js_raw 119,685 119,603 −82 (−0.1%) 🟢
octane-tsrx todo_js_gzip 39,038 39,009 −29 (−0.1%) 🟢
octane-tsrx todo_js_brotli 34,308 34,344 +36 (+0.1%) 🔴
octane-tsrx todo_app_brotli 1,881 1,884 +3 (+0.2%) 🔴
octane-tsrx todo_fw_raw 115,067 114,985 −82 (−0.1%) 🟢
octane-tsrx todo_fw_gzip 36,817 36,788 −29 (−0.1%) 🟢
octane-tsrx todo_fw_brotli 32,427 32,460 +33 (+0.1%) 🔴
octane-tsrx chat_js_raw 118,434 118,352 −82 (−0.1%) 🟢
octane-tsrx chat_js_gzip 38,853 38,824 −29 (−0.1%) 🟢
octane-tsrx chat_js_brotli 34,270 34,287 +17 (+0.0%) 🔴
octane-tsrx chat_app_gzip 2,715 2,714 −1 (−0.0%) 🟢
octane-tsrx chat_app_brotli 2,392 2,384 −8 (−0.3%) 🟢
octane-tsrx chat_fw_raw 112,669 112,587 −82 (−0.1%) 🟢
octane-tsrx chat_fw_gzip 36,138 36,110 −28 (−0.1%) 🟢
octane-tsrx chat_fw_brotli 31,878 31,903 +25 (+0.1%) 🔴
octane-tsrx weather_js_raw 154,747 154,665 −82 (−0.1%) 🟢
octane-tsrx weather_js_gzip 50,131 50,099 −32 (−0.1%) 🟢
octane-tsrx weather_js_brotli 43,730 43,717 −13 (−0.0%) 🟢
octane-tsrx weather_app_brotli 6,655 6,653 −2 (−0.0%) 🟢
octane-tsrx weather_fw_raw 132,596 132,514 −82 (−0.1%) 🟢
octane-tsrx weather_fw_gzip 42,262 42,230 −32 (−0.1%) 🟢
octane-tsrx weather_fw_brotli 37,075 37,064 −11 (−0.0%) 🟢
octane-tsrx bindings_js_raw 684,431 684,349 −82 (−0.0%) 🟢
octane-tsrx bindings_js_gzip 223,409 223,393 −16 (−0.0%) 🟢
octane-tsrx bindings_js_brotli 189,603 189,717 +114 (+0.1%) 🔴
octane-tsrx bindings_app_gzip 115,580 115,579 −1 (−0.0%) 🟢
octane-tsrx bindings_app_brotli 95,957 96,007 +50 (+0.1%) 🔴
octane-tsrx bindings_fw_raw 336,812 336,730 −82 (−0.0%) 🟢
octane-tsrx bindings_fw_gzip 107,829 107,814 −15 (−0.0%) 🟢
octane-tsrx bindings_fw_brotli 93,646 93,710 +64 (+0.1%) 🔴
octane-tsrx full_fw_raw 562,159 562,077 −82 (−0.0%) 🟢
octane-tsrx full_fw_gzip 168,880 168,856 −24 (−0.0%) 🟢
octane-tsrx full_fw_brotli 142,166 142,152 −14 (−0.0%) 🟢
octane-jsx js_raw 208,534 208,452 −82 (−0.0%) 🟢
octane-jsx js_gzip 65,312 65,285 −27 (−0.0%) 🟢
octane-jsx js_brotli 56,736 56,746 +10 (+0.0%) 🔴
octane-jsx app_brotli 2,405 2,406 +1 (+0.0%) 🔴
octane-jsx fw_raw 200,269 200,187 −82 (−0.0%) 🟢
octane-jsx fw_gzip 62,454 62,427 −27 (−0.0%) 🟢
octane-jsx fw_brotli 54,331 54,340 +9 (+0.0%) 🔴
octane-jsx full_fw_raw 562,159 562,077 −82 (−0.0%) 🟢
octane-jsx full_fw_gzip 168,880 168,856 −24 (−0.0%) 🟢
octane-jsx full_fw_brotli 142,166 142,152 −14 (−0.0%) 🟢

9 other measured values are unchanged.

Public-import reachability bundles (bytes)

target metric base head Δ
cli-spa-starter raw 100,429 100,347 −82 (−0.1%) 🟢
cli-spa-starter gzip 33,415 33,374 −41 (−0.1%) 🟢
cli-spa-starter brotli 29,351 29,386 +35 (+0.1%) 🔴
root-static-specialized raw 72,273 72,191 −82 (−0.1%) 🟢
root-static-specialized gzip 23,672 23,621 −51 (−0.2%) 🟢
root-static-specialized brotli 21,143 21,121 −22 (−0.1%) 🟢
root-chained-jsx raw 74,230 74,148 −82 (−0.1%) 🟢
root-chained-jsx gzip 24,202 24,155 −47 (−0.2%) 🟢
root-chained-jsx brotli 21,667 21,648 −19 (−0.1%) 🟢
root-static raw 186,639 186,557 −82 (−0.0%) 🟢
root-static gzip 58,199 58,164 −35 (−0.1%) 🟢
root-static brotli 50,516 50,562 +46 (+0.1%) 🔴
root-static-local raw 72,272 72,190 −82 (−0.1%) 🟢
root-static-local gzip 23,653 23,602 −51 (−0.2%) 🟢
root-static-local brotli 21,141 21,121 −20 (−0.1%) 🟢
hooks-state raw 84,022 83,940 −82 (−0.1%) 🟢
hooks-state gzip 27,623 27,585 −38 (−0.1%) 🟢
hooks-state brotli 24,568 24,567 −1 (−0.0%) 🟢
prop-attributes raw 84,276 84,194 −82 (−0.1%) 🟢
prop-attributes gzip 27,628 27,589 −39 (−0.1%) 🟢
prop-attributes brotli 24,613 24,654 +41 (+0.2%) 🔴
context raw 96,220 96,138 −82 (−0.1%) 🟢
context gzip 31,321 31,283 −38 (−0.1%) 🟢
context brotli 27,787 27,782 −5 (−0.0%) 🟢
hydrate-root raw 166,814 166,732 −82 (−0.0%) 🟢
hydrate-root gzip 52,615 52,580 −35 (−0.1%) 🟢
hydrate-root brotli 45,718 45,712 −6 (−0.0%) 🟢
deferred-hydration raw 230,816 230,734 −82 (−0.0%) 🟢
deferred-hydration gzip 72,282 72,245 −37 (−0.1%) 🟢
deferred-hydration brotli 62,191 62,179 −12 (−0.0%) 🟢
suspense-transition raw 141,698 141,616 −82 (−0.1%) 🟢
suspense-transition gzip 44,576 44,527 −49 (−0.1%) 🟢
suspense-transition brotli 39,181 39,152 −29 (−0.1%) 🟢
component-owned-effects raw 76,664 76,582 −82 (−0.1%) 🟢
component-owned-effects gzip 24,994 24,956 −38 (−0.2%) 🟢
component-owned-effects brotli 22,356 22,346 −10 (−0.0%) 🟢
binding-hooks raw 82,521 82,439 −82 (−0.1%) 🟢
binding-hooks gzip 27,278 27,241 −37 (−0.1%) 🟢
binding-hooks brotli 24,299 24,304 +5 (+0.0%) 🔴
binding-base-ui-vite raw 195,409 195,327 −82 (−0.0%) 🟢
binding-base-ui-vite gzip 61,353 61,320 −33 (−0.1%) 🟢
binding-base-ui-vite brotli 53,308 53,256 −52 (−0.1%) 🟢
binding-base-ui-esbuild raw 210,879 210,797 −82 (−0.0%) 🟢
binding-base-ui-esbuild gzip 68,236 68,199 −37 (−0.1%) 🟢
binding-base-ui-esbuild brotli 59,257 59,222 −35 (−0.1%) 🟢
binding-radix-vite raw 197,490 197,408 −82 (−0.0%) 🟢
binding-radix-vite gzip 61,964 61,929 −35 (−0.1%) 🟢
binding-radix-vite brotli 53,937 53,904 −33 (−0.1%) 🟢
binding-radix-esbuild raw 212,755 212,673 −82 (−0.0%) 🟢
binding-radix-esbuild gzip 68,826 68,791 −35 (−0.1%) 🟢
binding-radix-esbuild brotli 59,758 59,701 −57 (−0.1%) 🟢
binding-mantine-hooks-vite raw 86,079 85,997 −82 (−0.1%) 🟢
binding-mantine-hooks-vite gzip 28,245 28,205 −40 (−0.1%) 🟢
binding-mantine-hooks-vite brotli 25,115 25,116 +1 (+0.0%) 🔴
binding-mantine-hooks-esbuild raw 90,437 90,355 −82 (−0.1%) 🟢
binding-mantine-hooks-esbuild gzip 30,338 30,302 −36 (−0.1%) 🟢
binding-mantine-hooks-esbuild brotli 27,072 27,002 −70 (−0.3%) 🟢
binding-apollo-client-vite raw 337,900 337,818 −82 (−0.0%) 🟢
binding-apollo-client-vite gzip 103,677 103,642 −35 (−0.0%) 🟢
binding-apollo-client-vite brotli 90,448 90,462 +14 (+0.0%) 🔴
binding-apollo-client-esbuild raw 361,067 360,985 −82 (−0.0%) 🟢
binding-apollo-client-esbuild gzip 114,616 114,580 −36 (−0.0%) 🟢
binding-apollo-client-esbuild brotli 99,993 99,996 +3 (+0.0%) 🔴
binding-usehooks-ts-vite raw 86,845 86,763 −82 (−0.1%) 🟢
binding-usehooks-ts-vite gzip 28,464 28,426 −38 (−0.1%) 🟢
binding-usehooks-ts-vite brotli 25,343 25,337 −6 (−0.0%) 🟢
binding-usehooks-ts-esbuild raw 91,203 91,121 −82 (−0.1%) 🟢
binding-usehooks-ts-esbuild gzip 30,571 30,534 −37 (−0.1%) 🟢
binding-usehooks-ts-esbuild brotli 27,258 27,238 −20 (−0.1%) 🟢

36 other measured values are unchanged.

@trueadm
trueadm merged commit c213e87 into main Oct 6, 2026
51 of 53 checks passed
@trueadm
trueadm deleted the fix/trusted-capture-signal-lease branch October 6, 2026 12:13
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.

Trusted input capture signal updates reset controlled range values before bubble handlers

1 participant