Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

fix(components): call FormSchema.onChange with live form values - #5238

Merged
os-support-ai merged 1 commit into
mainfrom
claude/issue-4259-formschema-onchange-wiring
Aug 18, 2026
Merged

os-support-ai merged 1 commit into
mainfrom
claude/issue-4259-formschema-onchange-wiring

Conversation

@os-support-ai

Copy link
Copy Markdown
Collaborator

Fixes #4259

What was wrong

FormSchema declares four lifecycle callbacks and the form renderer destructures all four off schema in one block. Three were wired; onChange was 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/main before writing anything (the card body's anchors were stale, and the dispatch's were re-taken too):

measured on origin/main @ 513e614f0
destructure block lines 995 to 998 of packages/components/src/renderers/form/form.tsx
onChangeProp occurrences 1 — line 996, the destructure itself
counter-probe onDirtyChangeProp 5 hits, so the single hit is a real reading, not a broken pattern
siblings wired onDirtyChangeProp 1527 / 1562 / 1567, onSubmitProp 1694, onCancelProp 1772

The ruling this implements

Maintainer, 2026-08-17, verbatim 「同意」, recorded on the card:

Ruled: wire it. FormSchema.onChange gets called with live form values, using the same subscription plumbing onDirtyChange proves exists in the file. Enforce-or-remove is satisfied on the enforce side because it is the strictly cheaper arm here: wiring is additive; removal is a breaking public-type change plus a deprecation cycle for a hook whose siblings all work. Pin test: authored onChange fires on value change; absence of onChange changes nothing.

What changed

One new form.watch subscription 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: onAction guards, onDirtyChange subscribes unconditionally. The ruling's second half — absence of onChange changes nothing — is only literally true on the guarded pattern. An unconditional third form.watch on 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 defaultValues reset 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) => void signature — not a DOM event.

The top-level props strip: comment only

The strip drops onChange: _ignoredOnChange under 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: an onChange reaching 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:

  1. Positive — an authored onChange fires 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 (no nativeEvent, no target, no preventDefault).
  2. Negative, made observable — a probe wraps the useForm result and counts form.watch(callback) calls, so "no extra subscription" is measured rather than asserted. Authoring onChange costs exactly one subscription; authoring nothing costs none. Drop the guard and this goes red.
  3. Behavioural equivalence — a form with no onChange still seeds, types and submits identically.
  4. Reset ordering — a defaultValues reset 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.tsx to origin/main, kept the new test file. Observed matched predicted exactly, including which assertion fails in each case:

Test Predicted Observed
authored onChange fires with values RED RED — expected 0 to be greater than 0
no extra subscription when absent RED RED — expected 1 to be 2
behaves identically without onChange GREEN GREEN
reset not reported as a user edit RED, on the last assertion only RED — expected 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:

  • Test 3 in full. It is a regression guard for the negative half (wiring must not disturb callback-free forms), not a pin on the wiring.
  • The ordering assertion inside test 4 is vacuously green pre-fix: with onChange never called, received is 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. Likewise expect(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.tsx was restored from the commit afterwards — git diff HEAD empty, so the numbers above come from a byte-identical tree.

Gates run locally

All against the final commit, ec223d150:

gate result
pnpm exec vitest run packages/components/ 161 files / 1468 tests passed
pnpm --filter @object-ui/components run type-check pass (tsc --noEmit && tsc -p tsconfig.test.json; script name echoed, so not a zero-match)
eslint on both changed source files 0 errors (54 pre-existing warnings in the 3.1k-line file)
check:control-bytes pass — 4642 files scanned
check:phantom-deps pass
check:self-import pass
check-changeset-presence pass — 1 source file, 1 changeset
check-changeset-no-major pass

Declared 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 it type-check fails on unbuilt siblings, which reads exactly like a real error.

Changeset: @object-ui/components: minor, matching the closest precedent (honouring a previously-ignored declaration). Never major — the 39 packages share one fixed version group.

Scope

  • packages/types untouched. The onChange declaration 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 on form.zod.ts.
  • Found and filed separately, not fixed here: Form renderer: "a defaultValues reset is not a user edit" holds only for callers who do NOT memoize the callback #5235 — the "a reset is not a user edit" guarantee is delivered by the callback's identity changing each render, so a caller who wraps it in useCallback keeps a live subscription across the reset and does receive it. Measured: a stable-identity onChange gets { name: 'Loaded', note: 'from server' }. This is pre-existing on the onAction channel, onChange inherits 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

`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
@github-actions

Copy link
Copy Markdown
Contributor

✅ Console Performance Budget

Metric Value Budget
Main entry (gzip) 25.3 KB 350 KB
Entry file index-CEFD-fII.js —
Status PASS —

📦 Bundle Size Report

Package Size Gzipped
app-shell (index.js) 9.83KB 3.70KB
app-shell (runtime-config.js) 7.42KB 2.32KB
app-shell (types.js) 0.01KB 0.04KB
app-shell (urlParams.js) 8.92KB 3.41KB
auth (AuthContext.js) 0.31KB 0.24KB
auth (AuthGuard.js) 1.17KB 0.53KB
auth (AuthProvider.js) 25.13KB 5.40KB
auth (AuthShell.js) 3.49KB 1.40KB
auth (ForgotPasswordForm.js) 12.21KB 3.45KB
auth (LoginForm.js) 18.13KB 5.39KB
auth (PreviewBanner.js) 0.90KB 0.50KB
auth (RegisterForm.js) 6.64KB 2.21KB
auth (SocialSignInButtons.js) 9.60KB 3.89KB
auth (UserMenu.js) 3.40KB 1.22KB
auth (auth-gate-events.js) 1.29KB 0.66KB
auth (authStyles.js) 5.04KB 1.72KB
auth (createAuthClient.js) 40.21KB 10.79KB
auth (createAuthenticatedFetch.js) 6.34KB 2.43KB
auth (index.js) 2.71KB 1.22KB
auth (invitation-status.js) 1.22KB 0.70KB
auth (org-roles.js) 6.66KB 2.78KB
auth (phone-identifier.js) 1.11KB 0.66KB
auth (types.js) 0.59KB 0.35KB
auth (useAuth.js) 5.02KB 0.88KB
auth (useIsWorkspaceAdmin.js) 1.61KB 0.85KB
collaboration (CommentThread.js) 26.07KB 7.56KB
collaboration (LiveCursors.js) 3.17KB 1.27KB
collaboration (PresenceAvatars.js) 6.49KB 2.64KB
collaboration (PresenceProvider.js) 2.79KB 1.13KB
collaboration (index.js) 1.65KB 0.73KB
collaboration (useCollaborationTranslation.js) 6.05KB 2.52KB
collaboration (useCommentSearch.js) 1.98KB 0.88KB
collaboration (useConflictResolution.js) 7.75KB 1.86KB
collaboration (useMentionNotifications.js) 1.81KB 0.68KB
collaboration (usePresence.js) 6.33KB 1.84KB
collaboration (useRealtimeSubscription.js) 7.91KB 2.01KB
components (index.js) 506.08KB 113.32KB
core (index.js) 4.11KB 1.62KB
create-plugin (index.js) 10.08KB 3.26KB
data-objectstack (index.js) 159.03KB 44.08KB
fields (index.js) 237.07KB 59.46KB
i18n (LocalizationContext.js) 1.76KB 0.96KB
i18n (currency.js) 1.22KB 0.64KB
i18n (i18n.js) 4.28KB 1.75KB
i18n (index.js) 3.42KB 1.39KB
i18n (pickLocalized.js) 3.69KB 1.73KB
i18n (provider.js) 23.13KB 7.63KB
i18n (useDisplayLocale.js) 2.85KB 1.45KB
i18n (useObjectLabel.js) 27.60KB 6.63KB
i18n (useSafeTranslation.js) 7.77KB 3.13KB
layout (index.js) 39.16KB 10.97KB
mobile (MobileProvider.js) 0.92KB 0.49KB
mobile (ResponsiveContainer.js) 0.94KB 0.38KB
mobile (breakpoints.js) 1.51KB 0.70KB
mobile (createOfflineDataSource.js) 5.61KB 1.74KB
mobile (index.js) 1.50KB 0.62KB
mobile (offlineQueue.js) 3.91KB 1.35KB
mobile (pwa.js) 0.97KB 0.49KB
mobile (serviceWorker.js) 1.48KB 0.62KB
mobile (serviceWorkerSource.js) 3.41KB 1.48KB
mobile (useBreakpoint.js) 1.54KB 0.65KB
mobile (useGesture.js) 6.96KB 1.98KB
mobile (useOfflineSync.js) 1.99KB 0.72KB
mobile (usePullToRefresh.js) 2.53KB 0.85KB
mobile (useResponsive.js) 0.71KB 0.42KB
mobile (useResponsiveConfig.js) 1.36KB 0.63KB
mobile (useSpecGesture.js) 4.32KB 1.64KB
mobile (useTouchTarget.js) 1.01KB 0.54KB
permissions (MePermissionsProvider.js) 9.35KB 3.31KB
permissions (PermissionContext.js) 0.31KB 0.25KB
permissions (PermissionGuard.js) 0.89KB 0.45KB
permissions (PermissionProvider.js) 4.42KB 1.42KB
permissions (evaluator.js) 5.12KB 1.74KB
permissions (index.js) 0.91KB 0.41KB
permissions (store.js) 0.91KB 0.42KB
permissions (useFieldPermissions.js) 1.28KB 0.52KB
permissions (usePermissions.js) 1.81KB 0.83KB
plugin-ai (index.js) 15.75KB 3.80KB
plugin-calendar (index.js) 46.62KB 12.83KB
plugin-charts (index.js) 64.75KB 18.37KB
plugin-chatbot (index.js) 181.21KB 43.14KB
plugin-dashboard (index.js) 127.85KB 32.73KB
plugin-designer (index.js) 212.39KB 42.83KB
plugin-detail (index.js) 241.46KB 60.56KB
plugin-editor (index.js) 2.46KB 1.10KB
plugin-form (index.js) 123.77KB 30.07KB
plugin-gantt (index.js) 164.10KB 39.87KB
plugin-grid (index.js) 198.22KB 53.27KB
plugin-kanban (index.js) 52.93KB 14.60KB
plugin-list (index.js) 111.39KB 27.03KB
plugin-map (index.js) 20.02KB 6.58KB
plugin-markdown (index.js) 13.72KB 4.69KB
plugin-report (index.js) 42.84KB 11.77KB
plugin-timeline (index.js) 26.68KB 7.66KB
plugin-tree (index.js) 8.50KB 2.88KB
plugin-view (index.js) 83.81KB 20.49KB
providers (DataSourceProvider.js) 0.75KB 0.39KB
providers (MetadataProvider.js) 1.37KB 0.59KB
providers (ThemeProvider.js) 1.90KB 0.85KB
providers (UploadProvider.js) 11.66KB 3.50KB
providers (index.js) 0.44KB 0.22KB
providers (types.js) 0.01KB 0.04KB
react-runtime (index.js) 5.62KB 2.34KB
react (LazyPluginLoader.js) 3.77KB 1.33KB
react (SchemaRenderer.js) 31.56KB 10.70KB
react (data-invalidation.js) 5.05KB 2.08KB
react (index.js) 1.33KB 0.69KB
react (schema-input.js) 1.45KB 0.83KB
react (spec-input.js) 0.20KB 0.18KB
sdui-parser (codegen.js) 5.41KB 2.34KB
sdui-parser (index.js) 4.77KB 2.16KB
sdui-parser (input-type.js) 2.84KB 1.40KB
sdui-parser (parse.js) 10.76KB 3.17KB
sdui-parser (provenance.js) 3.66KB 1.82KB
sdui-parser (types.js) 0.29KB 0.24KB
sdui-parser (validate.js) 6.92KB 2.40KB
types (ai.js) 0.20KB 0.17KB
types (api-types.js) 0.20KB 0.18KB
types (app.js) 2.87KB 0.99KB
types (base.js) 0.20KB 0.18KB
types (blocks.js) 0.20KB 0.18KB
types (complex.js) 0.20KB 0.18KB
types (crud.js) 0.20KB 0.18KB
types (dashboard-filter-alias.js) 6.23KB 2.74KB
types (data-display.js) 0.20KB 0.18KB
types (data-protocol.js) 0.20KB 0.19KB
types (data.js) 0.20KB 0.18KB
types (designer.js) 1.87KB 0.85KB
types (disclosure.js) 0.20KB 0.18KB
types (error-code.js) 1.54KB 0.88KB
types (feedback.js) 0.20KB 0.18KB
types (field-types.js) 0.20KB 0.18KB
types (form.js) 0.20KB 0.18KB
types (http-retry.js) 4.32KB 2.02KB
types (index.js) 3.08KB 1.53KB
types (layout.js) 0.20KB 0.18KB
types (managed-by.js) 0.19KB 0.18KB
types (mobile.js) 2.59KB 1.31KB
types (navigation.js) 0.20KB 0.18KB
types (objectql.js) 0.20KB 0.18KB
types (overlay.js) 0.20KB 0.18KB
types (permissions.js) 0.20KB 0.18KB
types (plugin-scope.js) 0.20KB 0.18KB
types (record-components.js) 0.20KB 0.19KB
types (record-semantics.js) 1.28KB 0.67KB
types (registry.js) 0.20KB 0.18KB
types (reports.js) 0.20KB 0.18KB
types (spec-report.js) 5.05KB 1.93KB
types (system-fields.js) 3.33KB 1.54KB
types (theme.js) 0.20KB 0.18KB
types (ui-action.js) 3.40KB 1.71KB
types (views.js) 0.20KB 0.18KB
types (widget.js) 0.20KB 0.18KB

Size Limits

  • ✅ Core packages should be < 50KB gzipped
  • ✅ Component packages should be < 100KB gzipped
  • ⚠️ Plugin packages should be < 150KB gzipped

Copy link
Copy Markdown
Collaborator Author

ACCEPT. PM round 6, session session_01RV6yuVCxymHYE16PL9vQkE.

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 guard is the whole point, and it was reasoned rather than copied. Two subscription patterns sit within 40 lines of each other in this file — onAction guards, onDirtyChange does not — and the choice between them is exactly what makes "absence of onChange changes nothing" literally true instead of approximately true. An unconditional third form.watch on every form in the product would have been a behaviour change for callers who authored nothing, i.e. the opposite of the additive fix the ruling chose wiring for. Picking the guarded pattern, and saying why, is the difference between implementing the ruling and implementing half of it.
  • Layout phase, for the stated reason. Matching the defaultValues reset and both neighbouring subscriptions means a caller passing a fresh inline arrow has the subscription torn down around the reset, so a landing record is not reported to the host as if the user had edited every field it filled ([console 17.0.0-rc.0 @4a4829d0] Edit modal: a visibleWhen that flips false→true when the record lands wipes every rendered select's value, and the form latches broken #2968). No deviation, so nothing to justify.
  • The negative half was made observable, not asserted. A probe wrapping useForm and counting form.watch(callback) calls turns "no extra subscription" into a measurement: +1 with onChange, 0 without. Drop the guard and it goes red. Most deliveries would have written a comment here; this one wrote an instrument.
  • The positive assertion is on a value (name: 'Alice' → 'Bob') and on the absence of event shape (no nativeEvent, no target, no preventDefault). A call-count assertion would have passed for a callback handed a SyntheticEvent — the exact wrong-contract outcome the DOM channel would produce.
  • The comment correction is exactly scoped. The top-level strip claimed to protect an "our onChange" that did not exist until this change; it now names what it actually protects, and the block's behaviour is byte-identical. Correcting a comment that this PR makes true for the first time is in scope; changing the strip would not have been.

The part I want on the record

The 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 onChange never called, received is 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 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 toBe(1) ratchet as regression guards rather than pins on this change. A delivery that tells you which of its own assertions are load-bearing is worth more than one with more assertions.

Gates

21/21 check runs completed, zero failures. ACCEPT path surface (from git diff --name-only origin/main...FETCH_HEAD): .changeset/ + packages/components/src/renderers/form/form.tsx + the new test — no governed surface touched, probe run explicitly. packages/types untouched, as scoped. Changeset minor for @object-ui/components, matching the precedent for honouring a previously-ignored declaration.

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 useCallback keeps a live subscription across the reset and does receive it (measured: a stable-identity onChange gets {name: 'Loaded', note: 'from server'}). That is pre-existing on the onAction channel and inherited here by following the ruled plumbing — a semantics question, not a mechanical fix, and not something a fix PR should settle.


Generated by Claude Code

@os-support-ai
os-support-ai marked this pull request as ready for review August 18, 2026 19:54
@os-support-ai
os-support-ai added this pull request to the merge queue Aug 18, 2026
Merged via the queue into main with commit 5673576 Aug 18, 2026
21 checks passed
@os-support-ai
os-support-ai deleted the claude/issue-4259-formschema-onchange-wiring branch August 18, 2026 19:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FormSchema.onChange is a declared public callback the form renderer never calls — authoring it is a silent no-op

2 participants