Repository navigation
fix(components): call FormSchema.onChange with live form values - #5238
Conversation
`FormSchema` declares four lifecycle callbacks and the form renderer destructures all four together, but only three were wired. `onChangeProp` was destructured and never referenced again — the destructure was its only occurrence in the file — so authoring `onChange` on a form schema was a silent no-op with no warning and no type error. Wire it through the same `form.watch` plumbing the `onDirtyChange` and `onAction` channels use. The subscription is GUARDED on `onChangeProp` (like `onAction`, unlike `onDirtyChange`) so a schema authoring no `onChange` establishes no subscription at all, and it is LAYOUT-phase so a `defaultValues` reset is torn down around rather than reported to the host as a user edit. Also corrects the now-stale comment on the top-level `onChange` props strip, which claimed to protect an "our onChange" that did not yet exist. That block's behaviour is byte-identical. No change to `@object-ui/types`: the declaration was already correct. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RV6yuVCxymHYE16PL9vQkE
✅ Console Performance Budget
📦 Bundle Size Report
Size Limits
|
|
ACCEPT. PM round 6, session This is the cleanest delivery of the round, and the reason is that it took the ruling's second half as seriously as the first. Review
The part I want on the recordThe reverse verification predicted which assertion fails in each case, not merely which tests go red — and the observed failures match down to the message. Then it went further and volunteered what the tests do not prove: > the ordering assertion inside test 4 is vacuously green pre-fix: with That is a self-audit most reviews would not catch, disclosed rather than counted as evidence — and the liveness tail appended to make it non-vacuous is the right repair. Same for naming test 3 and the Gates21/21 check runs completed, zero failures. ACCEPT path surface (from Flipping ready and enqueueing. #4259 closes on merge — a callback that has been declared, typed, documented and inert is now called. #5235 is correctly filed rather than decided here: the "a reset is not a user edit" guarantee rests on the callback's identity changing each render, so a caller memoising with Generated by Claude Code |
Fixes #4259
What was wrong
FormSchemadeclares four lifecycle callbacks and the form renderer destructures all four offschemain one block. Three were wired;onChangewas destructured and then never referenced again, so authoring it was a silent no-op — no warning, no dev-mode notice, no type error. The declaration said it was supported.Premise re-verified against
origin/mainbefore writing anything (the card body's anchors were stale, and the dispatch's were re-taken too):origin/main@513e614f0packages/components/src/renderers/form/form.tsxonChangePropoccurrencesonDirtyChangeProponDirtyChangeProp1527 / 1562 / 1567,onSubmitProp1694,onCancelProp1772The ruling this implements
Maintainer, 2026-08-17, verbatim 「同意」, recorded on the card:
What changed
One new
form.watchsubscription beside its two siblings, plus a comment correction. Two properties are deliberate.It is guarded (
if (onChangeProp)). Two subscription patterns already exist in this file within 40 lines of each other and they are not interchangeable:onActionguards,onDirtyChangesubscribes unconditionally. The ruling's second half — absence ofonChangechanges nothing — is only literally true on the guarded pattern. An unconditional thirdform.watchon every form in the product would be a behaviour change for callers who authored nothing, which is the opposite of additive.It runs in the layout phase, matching the
defaultValuesreset and both subscriptions beside it. React runs every layout destroy before any layout create, so a caller passing a fresh inline arrow each render — the common shape — has the subscription torn down before the reset and re-established after. That is what keeps a record landing in edit mode from being reported to the host as if the user had edited every field it filled. A passive effect inverts the order (#2968). No deviation from layout phase, so nothing to justify here.The callback receives the form values, per its declared
(data) => voidsignature — not a DOM event.The top-level props strip: comment only
The strip drops
onChange: _ignoredOnChangeunder the comment "Prevent overwriting our onChange", and until now there was no "our onChange" — the thing that comment protected did not exist. It becomes true for the first time with this change, so the comment now names what it actually protects: anonChangereaching the form DOM element would fire with a SyntheticEvent, not with form values, which is a different contract altogether.The strip's behaviour is byte-identical — the destructured entry
onChange: _ignoredOnChange,is unchanged, nothing is re-routed, nothing double-fires. Only the comment text moved.Tests
New file
packages/components/src/renderers/form/__tests__/form-onchange-wiring.test.tsx, pinning both halves of the ruling plus the ordering property:onChangefires on a value change and is asserted on a value (name: 'Alice', then'Bob'), not a call count; and asserted not to be an event (nonativeEvent, notarget, nopreventDefault).useFormresult and countsform.watch(callback)calls, so "no extra subscription" is measured rather than asserted. AuthoringonChangecosts exactly one subscription; authoring nothing costs none. Drop the guard and this goes red.onChangestill seeds, types and submits identically.defaultValuesreset is not reported as a user edit, with a liveness tail proving the channel is still live afterwards.Reverse verification (predictions stated before running)
Restored
form.tsxtoorigin/main, kept the new test file. Observed matched predicted exactly, including which assertion fails in each case:onChangefires with valuesexpected 0 to be greater than 0expected 1 to be 2onChangeexpected undefined to deeply equal ObjectContaining {"name": "Edited"}Result: 3 failed / 1 passed, as predicted.
Two assertions stay green pre-fix and therefore pin nothing about this fix — stated plainly rather than counted as evidence:
onChangenever called,receivedis empty, so "the reset is not among the calls" is trivially true. On its own it cannot tell correct ordering from never firing. That is exactly why the liveness tail is appended — and the tail is the assertion that actually goes red. Likewiseexpect(withoutOnChange).toBe(1)in test 2 is a deliberate ratchet on pre-existing behaviour (a callback-free form establishes exactly one value subscription), not a pin on this change.The fix was committed before the reverse verification, and
form.tsxwas restored from the commit afterwards —git diff HEADempty, so the numbers above come from a byte-identical tree.Gates run locally
All against the final commit,
ec223d150:pnpm exec vitest run packages/components/pnpm --filter @object-ui/components run type-checktsc --noEmit && tsc -p tsconfig.test.json; script name echoed, so not a zero-match)eslinton both changed source filescheck:control-bytescheck:phantom-depscheck:self-importcheck-changeset-presencecheck-changeset-no-majorDeclared narrowing: the local test run is scoped to
packages/components/— the package that changed — rather than the whole farm, which CI runs exactly once anyway. The dependency closure was built first (pnpm --filter '@object-ui/components^...' build); without ittype-checkfails on unbuilt siblings, which reads exactly like a real error.Changeset:
@object-ui/components: minor, matching the closest precedent (honouring a previously-ignored declaration). Nevermajor— the 39 packages share one fixed version group.Scope
packages/typesuntouched. TheonChangedeclaration was already there and already correct; this is the renderer starting to honour it. No public type change, so nothing here collides with the in-flight work onform.zod.ts.useCallbackkeeps a live subscription across the reset and does receive it. Measured: a stable-identityonChangegets{ name: 'Loaded', note: 'from server' }. This is pre-existing on theonActionchannel,onChangeinherits it by following the ruled plumbing, and picking the right semantics is a design question rather than a mechanical fix — so it is filed unassigned for triage rather than decided in this PR.Generated by Claude Code