-
-
Notifications
You must be signed in to change notification settings - Fork 625
fix(form-core): prevent removeValue from auto-touching shifted siblings #2133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1605,7 +1605,15 @@ export class FormApi< | |
| batch(() => { | ||
| fieldsToValidate.forEach((nestedField) => { | ||
| fieldValidationPromises.push( | ||
| Promise.resolve().then(() => this.validateField(nestedField, cause)), | ||
| Promise.resolve().then(() => { | ||
| // If the field instance already exists, call validate directly | ||
| // to avoid auto-touching shifted siblings | ||
| const fieldInstance = this.fieldInfo[nestedField]?.instance | ||
| if (fieldInstance) { | ||
| return fieldInstance.validate(cause) | ||
| } | ||
| return this.validateField(nestedField, cause) | ||
| }), | ||
|
Comment on lines
+1609
to
+1634
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guard restoration with try/finally, and note the transient-state exposure. Two concerns with the temporary-touch approach:
The 🛡️ Proposed fix: ensure restoration on error paths if (options?.avoidTouch) {
const fieldInstance = this.fieldInfo[nestedField]?.instance
if (fieldInstance) {
const wasTouched = fieldInstance.state.meta.isTouched
if (!wasTouched) {
// Temporarily touch the field so validation runs, then restore
fieldInstance.setMeta((prev) => ({
...prev,
isTouched: true,
}))
}
- const result = await fieldInstance.validate(cause)
- if (!wasTouched) {
- fieldInstance.setMeta((prev) => ({
- ...prev,
- isTouched: false,
- }))
- }
- return result
+ try {
+ return await fieldInstance.validate(cause)
+ } finally {
+ if (!wasTouched) {
+ fieldInstance.setMeta((prev) => ({
+ ...prev,
+ isTouched: false,
+ }))
+ }
+ }
}
}🤖 Prompt for AI Agents |
||
| ) | ||
| }) | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.