Fix Array Swap Detection #2172
main fromrefs/pull/2172/head·merged by crutchcorn(GitHub profile, opens in a new tab) Fixes https://github.com/TanStack/form/issues/2018 for all adapters
Summary by CodeRabbit#
Bug Fixes
- Array form fields now properly re-render when array elements are reordered without changing the array length (e.g., swap, move operations).
Tests
- Added test coverage verifying array field re-rendering behavior across all framework adapters.
- 1
View your CI Pipeline Execution ↗ for commit 124ce20f7a9a709e02752dd480a61039782d6dab
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 50s View ↗ nx run-many --target=build --exclude=examples/**✅ Succeeded 9s View ↗
☁️ Nx Cloud last updated this comment at
2026-05-10 22:25:15UTC🚀 Changeset Version Preview#
7 package(s) bumped directly, 7 bumped as dependents.
🟨 Minor bumps#
Package Version Reason @tanstack/angular-form1.31.0 → 1.32.0 Changeset @tanstack/form-core1.31.0 → 1.32.0 Changeset @tanstack/react-form1.31.0 → 1.32.0 Changeset @tanstack/solid-form1.31.0 → 1.32.0 Changeset @tanstack/svelte-form1.31.0 → 1.32.0 Changeset @tanstack/vue-form1.31.0 → 1.32.0 Changeset @tanstack/react-form-nextjs1.31.0 → 1.32.0 Dependent @tanstack/react-form-remix1.31.0 → 1.32.0 Dependent @tanstack/react-form-start1.31.0 → 1.32.0 Dependent 🟩 Patch bumps#
Package Version Reason @tanstack/preact-form1.29.6 → 1.29.7 Changeset @tanstack/form-devtools0.2.26 → 0.2.27 Dependent @tanstack/lit-form1.24.0 → 1.24.1 Dependent @tanstack/react-form-devtools0.2.26 → 0.2.27 Dependent @tanstack/solid-form-devtools0.2.26 → 0.2.27 Dependent More templates
- @tanstack/form-example-angular-array
- @tanstack/form-example-angular-large-form
- @tanstack/form-example-angular-simple
- @tanstack/form-example-angular-standard-schema
- @tanstack/form-example-lit-array
- @tanstack/form-example-lit-large-form
- @tanstack/form-example-lit-simple
- @tanstack/form-example-lit-standard-schema
- @tanstack/form-example-lit-ui-libraries
- @tanstack/form-example-preact-simple
- @tanstack/form-example-solid-array
- @tanstack/form-example-solid-devtools
- @tanstack/form-example-solid-large-form
- @tanstack/form-example-solid-simple
- @tanstack/form-example-solid-standard-schema
- @tanstack/form-example-react-array
- @tanstack/form-example-react-compiler
- @tanstack/form-example-react-composition
- @tanstack/form-example-react-devtools
- @tanstack/form-example-react-dynamic
- @tanstack/form-example-react-expo
- @tanstack/field-errors-from-form-validators
- @tanstack/form-example-react-large-form
- @tanstack/form-example-react-next-server-actions
- @tanstack/form-example-react-next-server-actions-zod
- @tanstack/form-example-react-query-integration
- @tanstack/form-example-remix
- @tanstack/form-example-react-simple
- @tanstack/form-example-react-standard-schema
- @tanstack/form-example-react-tanstack-start
- @tanstack/form-example-react-ui-libraries
- @tanstack/form-example-svelte-array
- @tanstack/form-example-svelte-large-form
- @tanstack/form-example-svelte-simple
- @tanstack/form-example-svelte-standard-schema
- @tanstack/form-example-vue-array
- @tanstack/form-example-vue-simple
- @tanstack/form-example-vue-standard-schema
@tanstack/angular-form
npm i https://pkg.pr.new/@tanstack/angular-form@2172@tanstack/form-core
npm i https://pkg.pr.new/@tanstack/form-core@2172@tanstack/form-devtools
npm i https://pkg.pr.new/@tanstack/form-devtools@2172@tanstack/lit-form
npm i https://pkg.pr.new/@tanstack/lit-form@2172@tanstack/preact-form
npm i https://pkg.pr.new/@tanstack/preact-form@2172@tanstack/react-form
npm i https://pkg.pr.new/@tanstack/react-form@2172@tanstack/react-form-devtools
npm i https://pkg.pr.new/@tanstack/react-form-devtools@2172@tanstack/react-form-nextjs
npm i https://pkg.pr.new/@tanstack/react-form-nextjs@2172@tanstack/react-form-remix
npm i https://pkg.pr.new/@tanstack/react-form-remix@2172@tanstack/react-form-start
npm i https://pkg.pr.new/@tanstack/react-form-start@2172@tanstack/solid-form
npm i https://pkg.pr.new/@tanstack/solid-form@2172@tanstack/solid-form-devtools
npm i https://pkg.pr.new/@tanstack/solid-form-devtools@2172@tanstack/svelte-form
npm i https://pkg.pr.new/@tanstack/svelte-form@2172@tanstack/vue-form
npm i https://pkg.pr.new/@tanstack/vue-form@2172commit:
adad277crutchcorn(GitHub profile, opens in a new tab) closed this
Codecov Report#
:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 91.27%. Comparing base (
6892ed0) to head (adad277). :warning: Report is 210 commits behind head on main.Additional details and impacted files
@@ Coverage Diff @@ ## main #2172 +/- ## ========================================== + Coverage 90.35% 91.27% +0.91% ========================================== Files 38 59 +21 Lines 1752 2314 +562 Branches 444 568 +124 ========================================== + Hits 1583 2112 +529 - Misses 149 181 +32 - Partials 20 21 +1:umbrella: View full report in Codecov by Sentry. :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.
Sign in to join this conversation.
Caution
Review failed#
Pull request was closed or merged during review
📝 Walkthrough
Walkthrough#
Introduces
_arrayVersioncounter to field metadata to track structural array changes. Increments this counter on array mutations (swap, move, insert, remove) viabumpArrayVersionhelper. Updates all framework adapters—React, Preact, Vue, Svelte, Solid, and Angular—to watch this counter instead of array length for re-renders, ensuring components update when array values change without length changes.Changes#
Array Re-render on Value Change
packages/form-core/src/FieldApi.ts,packages/form-core/src/metaHelper.ts,packages/form-core/tests/FieldApi.spec.tsFieldMetaBaseadds_arrayVersion: number;defaultFieldMetainitializes it to0; test updated to expect the field.packages/form-core/src/metaHelper.tsbumpArrayVersionhelper and integrate it into array operation handlers (handleArrayMove,handleArrayRemove,handleArraySwap,handleArrayInsert); update metaHelper return to exposebumpArrayVersion.packages/form-core/src/FormApi.ts_arrayVersionduring field meta transform; callbumpArrayVersionafter array mutations inpushFieldValue,replaceFieldValue, andclearFieldValues.packages/react-form/src/useField.tsx,packages/react-form/tests/useField.test.tsx,packages/preact-form/src/useField.tsx,packages/preact-form/tests/useField.test.tsxuseFieldreactivity selector to trackstate.meta._arrayVersioninstead of array length; add tests validating re-render on swap.packages/vue-form/src/useField.tsx,packages/vue-form/tests/useField.test.tsxuseFieldreactivity selector to trackstate.meta._arrayVersionfor array-mode re-renders; add test validating re-render on swap.packages/svelte-form/src/Field.svelte,packages/svelte-form/tests/array-swap.svelte,packages/svelte-form/tests/array.test.tsFieldreactivestoreSubto trackstate.meta._arrayVersion; add test component and test suite validating re-render on swap.packages/solid-form/src/createField.tsx,packages/solid-form/tests/createField.test.tsxcreateFieldreactivity selector to trackstate.meta._arrayVersion; add test validating re-render on swap.packages/angular-form/src/tanstack-field.ts,packages/angular-form/tests/tanstack-field.spec.tsTanStackFieldreactivity selector to trackstate.meta._arrayVersion; add test validating re-render on swap..changeset/stale-berries-drop.md@tanstack/*-formpackages for array re-render fix.Sequence Diagram#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem#
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)#
✅ Passed checks (3 passed)
#2018by implementing array version tracking via _arrayVersion meta counter, updating all adapter implementations (react, angular, preact, solid, svelte, vue) to use this counter instead of array length for change detection, and adding comprehensive tests for swap functionality across all adapters.✨ Finishing Touches
📝 Generate docstrings
🧪 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