Skip to content
Source
Sign inSign up
TanStack/form

[v2] Fix: Move mounted fields onto the current field API after array mutations #2393

Openawdr74100(GitHub profile, opens in a new tab)wants to merge 1 commit intoalpha fromrefs/pull/2393/headopened

Showing 7 changed files with 28 additions and 0 deletions (loading 4).

x
0 of 7 viewed, 7 left
9 additions and 0 deletions.changeset/olive-moons-repeat.mdAdded
View file
@@ -0,0 +1,9 @@
+---
+'@tanstack/react-form': patch
+'@tanstack/form-core': patch
+'@tanstack/vue-form': patch
+---
+​
+Fix: Move mounted fields onto the current field API after array mutations
+​
+Removing or swapping array items kills and moves field APIs while the components rendering them stay mounted under the same name. Those components kept the field API they resolved on mount, so a value or error that shifted to their index never rendered. The form now tracks field API identity changes and adapters resolve their name again when it changes.
2 additions and 0 deletionspackages/form-core/src/FieldApi/FieldApi.lib.tsModified
View file
@@ -1215,6 +1215,7 @@
const previousPath = this.name
moveFieldToSegment(this, newSegment)
if (this.name !== previousPath) {
+ this.form._bumpFieldTreeVersion()
devtools().moveField?.(this, previousPath)
@@ -1230,6 +1231,7 @@
} = {},
killField(this, options)
+ this.form._bumpFieldTreeVersion()
_pruneIfUnused(): void {