Repository navigation
fix(react-form): [v2] provide field context inside app form ArrayField - #2434
LeCarbonator merged 2 commits into
Conversation
The app form replaces `Field` with a component that provides the field context, but keeps the plain `ArrayField`, so a registered field component rendered inside `form.ArrayField` or a form group's `ArrayField` throws "Field components must be used within a `form.Field` component", although the types offer it there. Let `createFieldWithContext` take the field subscription and use it with the array subscription for both, in React and Preact. Solid and Vue already provide the context for arrays.
🦋 Changeset detectedLatest commit: 1869c6d The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
View your CI Pipeline Execution ↗ for commit 1869c6d
☁️ Nx Cloud last updated this comment at |
LeCarbonator
left a comment
There was a problem hiding this comment.
LGTM! Thanks for tackling the oversight.
Don't worry about the zizmor report, we got some upstream things to fix before resolving this.
React unit tests are planned to be changed architecturally, but that'll take a while. The unit tests you added should do fine until then.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #2434 +/- ##
========================================
Coverage ? 93.58%
========================================
Files ? 30
Lines ? 483
Branches ? 41
========================================
Hits ? 452
Misses ? 30
Partials ? 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🎯 Changes
With
createFormHook, a registered field component insideform.ArrayField(or a form group'sArrayField) throwsTanStack Form: Field components must be used within a `form.Field` component.The types allow this: react-form's own type test renders<field.feedback.FieldInfo />insideform.ArrayField(createFormHook.test-d.tsx#L213-L216).The app form only wraps
FieldwithcreateFieldWithContext(ReactAppFormApi.lib.ts#L50-L58), soArrayFieldand the groupArrayFieldnever provideFieldContext. Preact has the same gap; Solid and Vue already provide the context there.createFieldWithContextnow takes the field subscription hook (defaultuseValueFieldSubscription) and both array components passuseArrayFieldSubscription, so they still rerender only on length and_arrayVersionchanges. Same fix in Preact, whose groupArrayFieldgoes throughform.ArrayField. Also updated thefieldComponentJSDoc.Added a test per adapter in
createFormHook.spec.tsx: a field component insideform.ArrayFieldand inside a groupArrayFieldrenders, updates afterpushValue, and a child value change doesn't rerender the array children. Onalphait fails in React (normal and strict) and Preact with:It passes with the fix, and
pnpm test:prpasses locally (28 projects affected).✅ Checklist
pnpm test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit