-
-
Notifications
You must be signed in to change notification settings - Fork 681
fix(form-core): abort pending field validations on reset #2382
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
Open
lunaxislu
wants to merge
2
commits into
TanStack:main
Choose a base branch
from
lunaxislu:fix/reset-stale-field-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+166
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@tanstack/form-core': patch | ||
| --- | ||
|
|
||
| Abort pending field validations when resetting the form so results for pre-reset values cannot reapply stale field errors. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: TanStack/form
Length of output: 200
🏁 Script executed:
Repository: TanStack/form
Length of output: 50370
🏁 Script executed:
Repository: TanStack/form
Length of output: 50369
🤖 get_repo_knowledge executed:
get_repo_knowledge TanStack/form /tmp/coderabbit-repo-knowledge/tanstack-form-324d0ba3/architecture /tmp/coderabbit-repo-knowledge/tanstack-form-324d0ba3/learningsLength of output: 30437
Keep validation counters generation-safe across
FormApi.reset.resetsets each field's meta todefaultFieldMeta, which resets_pendingValidationsCountandisValidating.FieldApi.validateAsyncstill callsendValidation()when an aborted validation settles. If validation B starts before validation A settles, A can decrement B's counter and clearisValidatingwhile B is pending. Make completion tracking generation-aware and add a regression test for this sequence.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for flagging this. I reproduced the counter race using deferred promises, with A using
onChangeAsyncand B usingonBlurAsync. Using different validation causes avoids the same-cause debounce timer bookkeeping issue discussed in #2373.I ran the same four-case probe against isolated source copies of the PR base (
57a855b4) and the current PR head (0bcaae12):In both failing cases, B starts with
_pendingValidationsCount: 1andisValidating: true. When A settles, these become0andfalseeven though B has not settled. On the PR head, A's signal is aborted as expected, but the outer completion path still callsendValidation(). In the no-reset controls, A's completion correctly changes the count from 2 to 1 and keepsisValidatingtrue.So the finding is valid, and this isolated case also exists on the PR base rather than being introduced by this change. This PR prevents stale field errors from being reapplied; it does not fix completion accounting across reset. The existing A/B test in this PR checks error application, not counter ownership.
My preference is to track the counter race in a separate issue/PR, since fixing completion ownership needs additional coverage for ordinary overlapping and linked-field validations. Would maintainers prefer that separation, or should I extend this PR to address both? I have not changed the implementation or marked this thread resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunaxislu, thank you for the detailed reproduction.A separate issue and PR are appropriate. The counter race exists on the PR base, and the current PR does not introduce it. This PR should remain limited to preventing stale field errors after
FormApi.reset().The follow-up should make
FieldApi.validateAsynccompletion ownership generation-aware. It should include the reset sequence and existing overlapping and linked-field validation cases.The finding remains valid, but it is not a blocker for the stated reset-error fix. Would you like me to open a follow-up GitHub issue for the counter race?
🐇
You are interacting with an AI system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked separately in #2384, with the proposed fix in #2385 (based directly on main). The follow-up includes direct and linked-field cases with and without reset: both reset cases fail before the fix and all four pass afterward. Full local PR checks pass. No code changes were added to this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunaxislu, thank you for tracking this in#2384and#2385.The separate follow-up keeps this PR focused on preventing stale field errors after
FormApi.reset(). The reported coverage for direct and linked-field validation cases addresses the required counter-ownership scenarios.You are interacting with an AI system.