🎯 Changes#
Fixes #2390.
Field components registered through createFormHook (getFormHookHelpers().fieldComponent) rendered once and then stopped updating:
wrapField passed the same field API object on every render. The parent Field rerendered its slot, but Vue skipped updating the injected component because its props were unchanged, and the child's reads of the field API getters weren't tracked.
Field provided fieldApi.value once during setup. useField replaces that API when resetVersion changes, so after form.reset() the injected component kept writing to the stale instance.
This PR:
- Makes
Field provide a computed that returns a tracked view of the current field API (trackFieldApi in fieldSubscriptions.lib.ts) instead of the setup-time instance.
trackFieldApi wraps the field API in a Proxy. Its get trap reads the field's existing subscription, so Vue tracks reads made while the injected component renders. Methods from the prototype chain are bound to the underlying field API, so they never run with the proxy as this. Own properties, including the attached field components, are returned unchanged. set forwards to the target.
- Makes
wrapField read the computed while rendering, so a replaced field API (after reset) reaches the component as a new prop.
- Updates the comment in
createFieldComponent that assumed field APIs were stable and that the parent subscription covered injected components.
- Adds two regression tests in
tests/adapter.spec.tsx. Both fail on alpha and pass with this change:
rerenders composed field components when field state changes
keeps composed field components connected after form reset
Trade-off to review: the field prop that injected components receive is now a proxy, so field === <slot field> is false. Behaviour and types are unchanged. Other approaches I considered were forcing child updates with non-stable slots, or remounting with a changing key. Both felt more fragile.
I also verified the change against an external spike app (Vue 3.6.0-rc.8) that uses the large-form TextField pattern with no workarounds: submit-time errors, live revalidation, server errors from createValidationError, nested paths, SSR rendering and hydration all pass. One remaining failure there is a separate ArrayField removal issue, reported in #2391 and not addressed here.
✅ Checklist#
🚀 Release Impact#
Summary by CodeRabbit#
Bug Fixes
- Field components created with form hooks now update when field values or validation states change.
- Field components remain connected to the latest field state after resetting a form.
- Composed fields now keep values, errors, and accessibility states synchronized.
Tests
- Added coverage for reactive updates, form resets, validation errors, and
aria-invalid state changes.
📝 Walkthrough
Walkthrough#
Field components registered through
createFormHooknow receive tracked field APIs. They rerender when field state changes and remain connected afterform.reset(). Adapter tests cover validation updates, accessibility state, and post-reset input.Changes#
Vue field component reactivity
packages/vue-form/src/AppForm/contexts.lib.ts,packages/vue-form/src/VueForm/fieldSubscriptions.lib.tsComputedRef<AnyInternalFieldApi>.trackFieldApitracks selection changes and preserves bound API methods.packages/vue-form/src/VueForm/Components.lib.ts,packages/vue-form/src/AppForm/fieldComponentHelpers.lib.tsfield.valueas their field prop.packages/vue-form/tests/adapter.spec.tsx,.changeset/quiet-fields-follow.mdaria-invalidupdates, and continued input handling after reset. The changeset declares a patch release.Priority: ➖ Normal
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: 🟡 Moderate · up to
34825Composed ArrayField components can continue showing stale validation errors and accessibility state until the array structure changes. Update their tracked selection and add regression coverage before merging.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#2390].createFieldComponentprovides a computed field API view throughtrackFieldApi, and the view tracks subscribed field state and API repla…#2390]. The context type updates, tracking proxy, field wrapper update, regression tests, and Vue form changeset directly support reactive injected fields and field API replac…Full details: Docstring Coverage
Explanation
Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 5 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share