fix(react-form): [v2] provide field context inside app form `ArrayField` #2434
alpha fromrefs/pull/2434/head·merged by LeCarbonator(GitHub profile, opens in a new tab) 🎯 Changes#
With createFormHook, a registered field component inside form.ArrayField (or a form group's ArrayField) throws TanStack 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 /> inside form.ArrayField (createFormHook.test-d.tsx#L213-L216).
The app form only wraps Field with createFieldWithContext (ReactAppFormApi.lib.ts#L50-L58), so ArrayField and the group ArrayField never provide FieldContext. Preact has the same gap; Solid and Vue already provide the context there.
createFieldWithContext now takes the field subscription hook (default useValueFieldSubscription) and both array components pass useArrayFieldSubscription, so they still rerender only on length and _arrayVersion changes. Same fix in Preact, whose group ArrayField goes through form.ArrayField. Also updated the fieldComponent JSDoc.
Added a test per adapter in createFormHook.spec.tsx: a field component inside form.ArrayField and inside a group ArrayField renders, updates after pushValue, and a child value change doesn't rerender the array children. On alpha it fails in React (normal and strict) and Preact with:
FAIL |@tanstack/react-form: normal (chromium)| tests/createFormHook.spec.tsx:46 > createFormHook > provides field context to field components inside an ArrayField
Error: TanStack Form: Field components must be used within a `form.Field` component.
It passes with the fix, and pnpm test:pr passes locally (28 projects affected).
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with
pnpm test:pr, or these tests do not apply to this pull request. - I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
- Bug Fixes
- Registered field components now render correctly inside top-level and grouped ArrayField render callbacks in React and Preact forms, rather than throwing an error.
- Array item updates continue to avoid unnecessary field component re-renders.
- 1
Important
Review skipped#
Review was skipped as selected files did not have any reviewable changes.
⚙️ Run configuration
-
- Configuration used: Repository: TanStack/form/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
cad90d02-574e-45cc-9261-fb94862bac8e
📥 Commits
-
Reviewing files that changed from the base of the PR and between deafb2d857876f6e10057a3b837a042f7356883f and 1869c6d826743df4cb74f38c9f51ba4acaafcb52.
You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
- 🔍 Trigger review
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:
729b90c0-53d5-48e8-ac10-865ffd451475
📥 Commits
-
Reviewing files that changed from the base of the PR and between 3d3907734521024f54fd6f66e4fd591ee9abcae4 and deafb2d857876f6e10057a3b837a042f7356883f.
📒 Files selected for processing: 7
-
.changeset/quiet-arrays-share.mdpackages/preact-form/src/AppForm/Components.lib.tsxpackages/preact-form/tests/createFormHook.spec.tsxpackages/react-form/src/AppForm/Components.lib.tsxpackages/react-form/src/AppForm/ReactAppFormApi.lib.tspackages/react-form/src/AppForm/getFormHookHelpers.public.tspackages/react-form/tests/createFormHook.spec.tsx
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
-
📝 Walkthrough
-
React and Preact App Form
ArrayFieldcomponents now use array-field subscriptions to provide field context. Tests cover strict field components in direct and grouped arrays, including item counts and render counts.Changes: ArrayField field context
Layer / File(s) Summary ArrayField context and validation
packages/react-form/src/AppForm/Components.lib.tsx,packages/react-form/src/AppForm/ReactAppFormApi.lib.ts,packages/preact-form/src/AppForm/Components.lib.tsx,packages/react-form/tests/createFormHook.spec.tsx,packages/preact-form/tests/createFormHook.spec.tsx,packages/react-form/src/AppForm/getFormHookHelpers.public.ts,.changeset/quiet-arrays-share.mdcreateFieldWithContextaccepts a subscription hook, and React and Preact App FormArrayFieldcomponents pass the array-field subscription hook. Tests check strict field components in direct and grouped arrays, item counts, and render counts. The helper documentation mentionsArrayField, and a changeset declares patch releases for both packages.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~12 minutes
Change: Bug fix
Suggested reviewers:
lecarbonator,crutchcorn
Merge Risk: ⚪ Minimal · up to
deafb-
The ArrayField context change appears ready to merge after normal checks. No concrete issue remains that would block registered field components from rendering in the supported array contexts.
Pre-merge checks:
4 · 1-
Failed checks: 1 warningCheck name Status Explanation Resolution Docstring Coverage Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 6 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold. Passed checks: 4 passed-
Check name Status Explanation Title check The title clearly identifies the primary fix: providing field context inside App Form ArrayField components for React Form. It is concise and specific. Description check The description explains the issue, implementation, affected adapters, tests, test results, and release impact. All required template sections are present and the checklist is completed accurately. Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 6 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment `@coderabbitai help` to get the list of available commands.-
View your CI Pipeline Execution ↗ for commit 1869c6d826743df4cb74f38c9f51ba4acaafcb52
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 1m 24s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 1s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-21 07:30:20UTCMore templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-basic
- @tanstack/form-example-angular-basic-splitting-form
- @tanstack/form-example-angular-field-groups
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-multi-step-wizard
- @tanstack/form-example-angular-query-integration
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-preact-array
- @tanstack/form-example-preact-basic
- @tanstack/form-example-preact-basic-splitting-form
- @tanstack/form-example-preact-field-groups
- @tanstack/form-example-preact-large-form
- @tanstack/form-example-preact-multi-step-wizard
- @tanstack/form-example-preact-query-integration
- @tanstack/form-example-preact-simple
- @tanstack/form-example-preact-standard-schema
- @tanstack/form-example-react-array
- @tanstack/form-example-react-basic
- @tanstack/form-example-react-basic-splitting-form
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-expo
- @tanstack/form-example-react-field-groups
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-multi-step-wizard
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-next-server-actions-zod
- @tanstack/form-example-react-nextjs
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-standard-schema
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-integration-dnd-kit
- @tanstack/form-example-react-ui-integration-shadcn
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-basic
- @tanstack/form-example-solid-basic-splitting-form
- @tanstack/form-example-solid-field-groups
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-multi-step-wizard
- @tanstack/form-example-solid-query-integration
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-basic
- @tanstack/form-example-svelte-basic-splitting-form
- @tanstack/form-example-svelte-field-groups
- @tanstack/form-example-svelte-large-form
- @tanstack/form-example-svelte-multi-step-wizard
- @tanstack/form-example-svelte-query-integration
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-large-form
- @tanstack/form-example-vue-multi-step-wizard
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-basic
- @tanstack/form-example-lit-basic-splitting-form
- @tanstack/form-example-lit-field-groups
- @tanstack/form-example-lit-large-form
- @tanstack/form-example-lit-multi-step-wizard
- @tanstack/form-example-lit-query-integration
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@2434@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@2434@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@2434@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@2434@tanstack/preact-form
npm i https://pkg.pr.new/@tanstack/preact-form@2434@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@2434@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@2434@tanstack/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2434@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@2434@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@2434@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2434@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@2434@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@2434commit:
1869c6dLeCarbonator(GitHub profile, opens in a new tab) approved these changes
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.
:warning: Please install the
to ensure uploads and comments are reliably processed by Codecov.
Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :warning: Please upload report for BASE (
alpha@e6fd415). Learn more about missing BASE report. :exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.Additional details and impacted files
@@ Coverage Diff @@ ## alpha #2434 +/- ## ======================================== Coverage ? 93.58% ======================================== Files ? 30 Lines ? 483 Branches ? 41 ======================================== Hits ? 452 Misses ? 30 Partials ? 1:umbrella: View full report in Codecov by Harness. :loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
LeCarbonator(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 1869c6d826743df4cb74f38c9f51ba4acaafcb52
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