Closes #2411
🎯 Changes#
A form from extendForm could not be passed to a field group made with the base hook's withFieldGroup, even though it only adds components.
Why: FieldComponent, LensFieldComponent and FormGroupComponent marked ExtendedApi (the component map) as in out, so it had to match exactly.
But ExtendedApi is only used in the type of the field passed to children. A form with more components gives children a field with more properties, which is always safe. So out is the right variance.
The fix: in out ExtendedApi → out ExtendedApi in those 3 types.
Test: a new case in createFormHook.test-d.tsx:
- A form from
extendForm (extra field and form components) is accepted by a base withFieldGroup group.
- A base form is still accepted.
- The other way round still errors: a base form passed to an extended group is rejected, because it lacks
ExtendedField.
Before (main): the new test fails with the error from the issue.
After (this PR): 0 type errors, and TypeScript 5.4 to 5.9 all pass.
✅ Checklist#
🚀 Release Impact#
Summary by CodeRabbit#
New Features
- Field groups created with a base hook can now accept forms extended with additional components.
Bug Fixes
- Improved type compatibility for fields and field groups, allowing extended forms where appropriate while rejecting forms that lack required extended components.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: TanStack/form/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
25b3521f-94f7-4af5-8f17-810afe5f41e7📥 Commits
Reviewing files that changed from the base of the PR and between 555509cd941ae6ea3a2966ef3c879a322b3b383c and 12c07989b3423e9b382147b2622e1971e46c69b0.
📒 Files selected for processing (4)
.changeset/wide-fields-extend.mdpackages/react-form/src/useField.tsxpackages/react-form/src/useFormGroup.tsxpackages/react-form/tests/createFormHook.test-d.tsxIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
The change declares
ExtendedApias covariant in field and field-group component types. A type test checks assignments between forms created by a base hook and its extended hook. A patch changeset records the update.Changes#
Form component compatibility
packages/react-form/src/useField.tsx,packages/react-form/src/useFormGroup.tsx,packages/react-form/tests/createFormHook.test-d.tsx,.changeset/wide-fields-extend.mdFieldComponent,LensFieldComponent, andFormGroupComponentdeclareExtendedApias covariant. The type test checks that a base field group accepts base and extended forms, and that an extended field group rejects a base form withoutExtendedField. The changeset records the patch.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Low
Merge Risk: ⚪ Minimal · up to
12c07This is a type-level change that lets forms from extendForm be passed to base withFieldGroup components. Base forms passed to extended groups are still rejected. No runtime behavior changes, and no merge-blocking risk was found.
Security Architecture Review#
Security architecture risk: ⚪ Minimal · up to
12c07The reviewed change widens compile-time compatibility without changing runtime execution or privileges. The added type test preserves rejection of forms that lack components required by an extended field group. No introduced or worsened security risk was identified in this change.
Retained concerns No architecture-level concerns identified.
Security review details
Security Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
#2411] requires anextendFormform to be accepted by a basewithFieldGroupwhen the group uses base components, while the reverse assignment remains rejected. The PR changesExtendedApit…#2411], and the…✨ 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