Repository navigation
fix: align delegated discrete event commit boundary with React batchedUpdates - #927
Merged
Merged
Conversation
…dUpdates The outermost delegated dispatch of a discrete event now flushes synchronously only when a controlled `value`/`checked` host armed a state restore during that dispatch; every other handler update stays in the microtask batch, matching React 19's `batchedUpdates`. Script-dispatched events (`dispatchEvent`, `click()`, `requestSubmit()`) therefore no longer publish a commit mid-dispatch that React would publish only after the dispatching script yields, while browser-dispatched events are unaffected because the microtask checkpoint runs before the next native listener and the default action. Adds a commit-timing suite with an inline React 19 oracle, a real-browser probe for trusted versus script clicks on both renderers, re-pins the conformance tests that encoded the previous boundary, and documents the contract in differences-from-react. Co-Authored-By: Claude Fable 5.1 <[email protected]>
trueadm
marked this pull request as ready for review
September 2, 2026 00:07
…ts in the test rig The first CI run of the restore-gated event boundary exposed 19 tests in 8 files that only run in projects outside the local matrix (octane-profile, octane-signals*, rainbowkit, tanstack-hotkeys, colorful, usehooks-ts), and the local full run two more (colorful adapted pointer probes, drei Html) plus a genuine runtime ordering defect the new timing made reachable. Runtime: `setValue` now writes the DOM property before syncing the value attribute on updates, as on mount and as React's updateInput does. When the commit lands after a reset button's default action (any script-dispatched click), the native reset has left the control NON-DIRTY, so the old attribute-first write moved the live value itself, skipped the property write, and left the control non-dirty where React marks it dirty. Regression: `ResetForm` in discrete-dispatch-commit-timing (Octane + React 19 oracle); the test fails on the previous order with `expected 'drift' to be ''`. Tests: - _helpers.ts: flushEffects()/nextPaint() flushSync the queued commit before draining passive effects, so the deterministic "browser settles" stand-in includes the microtask commit a script-dispatched event leaves behind. - devtools-runtime, signals-rendering, colorful hydration, usehooks-ts package-boundary, drei Html: pin the new timing explicitly. - colorful adapted pointer/touch helpers dispatch inside flushSync, so each simulated event commits on its own like upstream's act-wrapped fireEvent. - Audit ledgers: refresh the pinned hashes of testing-library's differential.test.ts and drei's html.test.ts / runtime-evidence.json (lint and all four React-parity shards failed on the mismatch). Co-Authored-By: Claude Fable 5.1 <[email protected]>
Co-Authored-By: Claude Fable 5.1 <[email protected]>
14 of 21 tasks
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
batchedUpdates: the outermost dispatch of a discrete event flushes synchronously only when a controlledvalue/checkedhost armed a state restore during that dispatch; every other handler update stays in the microtask batch.dispatchEvent,click(),requestSubmit()from outside code) no longer publish a commit mid-dispatch that React would publish only after the dispatching script yields. Browser-dispatched events are observationally unchanged: the microtask checkpoint runs before the next native listener and before the default action.Why
batchedUpdates$1(react-dom-client) flushes sync work at the end of the outermost event only when a controlled restore is pending; verified empirically in this repo's jsdom and in real Chromium.Changes
packages/octane/src/runtime.ts:maybeFlushDiscreteis gated onpendingRestores.length > 0; comments onDISCRETE_EVENTS,flushSync, the flush re-entrancy guard, and the capture-only fallback state the actual policy.packages/octane/tests/discrete-dispatch-commit-timing.test.ts(+_fixtures/dispatch-commit-timing.tsrx) with an inline React 19 oracle;conformance/scheduler-priority.test.tsrewritten to the React policy.tests/browser/event-boundaries: newcommit-timingprobe for Octane (_fixtures/event-commit-timing.tsrx) and a hand-written React counterpart — a trusted click commits before a later nativedocumentlistener runs; a script click commits only after the dispatching script yields; both renderers agree.act()/flushSync(); contract tests for async actions, nested roots, react-hosted islands, and the view-transition in-flight path re-pinned to the React-consistent behavior.packages/octane/src/runtime.tssetValue: controlledvalueupdates write the DOM property before syncing thevalueattribute (ReactupdateInputorder, and Octane's own mount order). The new timing made this reachable: a script click on a reset button that also clears state now commits after the native reset, which leaves the control non-dirty; attribute-first moved the live value and skipped the property write, leaving it non-dirty where React marks it dirty (user-event's value tracker relies on that write — this is what broke the tanstack-formreset in onSubmitcase). RegressionResetFormindiscrete-dispatch-commit-timingfor Octane and the React 19 oracle; red on the old order (expected 'drift' to be '').packages/octane/tests/_helpers.ts:flushEffects()/nextPaint()nowflushSync(() => {})before draining passive effects, so the deterministic "browser settles" stand-in includes the microtask commit a script-dispatched event leaves queued. That keeps binding tests written asel.click(); flushEffects(); expect(DOM)(rainbowkit, tanstack-hotkeys) valid without per-site edits.devtools-runtime.test.tsrx(script click commits in the microtask, subscriber notified then),signals-rendering.test.ts(event-owned batch settled before observing the DOM),colorfulhydrationsettle()(commit, then passive effects), theusehooks-tspackage-boundary consumer (flushSync(() => button.click())), thedreiHtml click, and thecolorfuladapted pointer/touch helpers, which now commit per simulated event the way upstream's act-wrappedfireEventdoes (two script dispatches in one task no longer coalesce into oneonChange).testing-library/tests/differential.test.tsand of thedreiHtml test (plus theruntime-evidence.jsonthat pins it);pnpm react-parity:validatepasses.docs/differences-from-react.mdscheduling section; changeset (octanepatch).Validation
pnpm format:checkpnpm typecheck— targeted:tsgo --noEmit -p packages/octane/tsconfig.jsonand-p packages/testing-library/tsconfig.json(the full script was not run)pnpm test— full root script on the pushed head after the CI follow-up: 2543 test files / 27,850 tests pass across every vitest project (the first CI run exposed 19 tests in 8 files outside the initially targeted projects, and the local full run three more; all now pass).pnpm react-parity:validate(manifests + evidence hashes current) andpnpm sync(no generated changes)node benchmarks/event-delegation/run.mjs octane-tsrx 10— baseline 4.80 ms (p95 6.70) vs candidate 4.38 ms (p95 7.10), all correctness and deterministic work gates pass (this burst exercises the unchanged controlled-restore path, so it is the semantic control; no speed claim is made)Risk / follow-ups
dispatchEventneedact()/flushSync(), as with React.@octanejs/testing-library'sfireEventis alreadyflushSync-wrapped and is unaffected.touchstart/touchmoveroot listeners remainpassive: false(React 17+ registers them passive), and continuous events still have no separate priority lane.pnpm typecheck:fileson test files that import.tsrxfixtures reports TS2307; this is pre-existing (tests are excluded from the octane tsconfig).Provenance
agent-authored)🤖 Generated with Claude Code
Note
Medium Risk
Changes core event scheduling and controlled-input DOM writes—behavioral breaking for tests or integrations that assumed every discrete event committed synchronously, though it matches React and is heavily regression-tested.
Overview
Aligns Octane’s delegated discrete-event scheduling with React 19
batchedUpdates: the outermostclick/input/etc. dispatch only sync-flushes when a controlledvalue/checkedhost armed a state restore; ordinary handler updates stay in the microtask batch, so script dispatches (dispatchEvent,click(),requestSubmit()) no longer commit mid-dispatch while React would commit after the script yields. Native listeners and nested roots therefore see the same pre-commit DOM as under React; browser-dispatched events stay observationally similar because the microtask runs before later listeners.Controlled
valuecommits now write the DOM property before syncing thevalueattribute (ReactupdateInputorder), fixing reset-button + controlled-input cases where attribute-first left the control non-dirty.Adds
discrete-dispatch-commit-timingtests with a React 19 oracle, real-browser commit-timing probes, and re-pins many suites to useact()/flushSync()where bare dispatches used to assume synchronous commits. Test helpers (flushEffects/nextPaint) flush the microtask queue first; docs and a patch changeset document the behavior shift.Reviewed by Cursor Bugbot for commit 0364327. Bugbot is set up for automated code reviews on this repo. Configure here.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.