fix(form-core): don't auto-touch shifted siblings on array mutation #2225
Openchatman-media(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/2225/headopened - packages/form-core/src/FormApi.ts lines 1920 to 1937@@ -1918,3 +1918,20 @@19181918 fieldsToValidate.forEach((nestedField) => {19191919 fieldValidationPromises.push(1920- Promise.resolve().then(() => this.validateField(nestedField, cause)),1920+ Promise.resolve().then(() => {1921+ // These fields were merely shifted by an array mutation, the user1922+ // never interacted with them. Their value did change, so they1923+ // still need to be validated, but `validateField` auto-touches as1924+ // a side-effect — which would spuriously mark untouched siblings1925+ // as touched. Remember the prior touched state and restore it for1926+ // fields that weren't touched before.1927+ const fieldInstance = this.fieldInfo[nestedField]?.instance1928+ const wasTouched = fieldInstance?.store.state.meta.isTouched ?? true1929+1930+ const result = this.validateField(nestedField, cause)1931+1932+ if (fieldInstance && !wasTouched) {1933+ fieldInstance.setMeta((prev) => ({ ...prev, isTouched: false }))1934+ }1935+1936+ return result1937+ }),
chatman-media(GitHub profile, opens in a new tab) linked this to fix #2131
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
Array field validation now preserves touched state for shifted siblings while still returning validation errors. Regression tests cover forwarded array validation and
removeFieldValueto confirm untouched shifted fields stay untouched.Changes#
Array shift touched-state fix
packages/form-core/src/FormApi.tsvalidateArrayFieldsStartingFromsnapshots each shifted field’s touched state, runs validation, and restores untouched mounted fields back toisTouched = false.packages/form-core/tests/FieldGroupApi.spec.ts,packages/form-core/tests/FormApi.spec.tsremoveFieldValue('names', 2)flows.Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem#
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
#2131by keeping array-shifted siblings untouched while still revalidating them.✨ 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