Fix #166: Clear async validation promise on rejection to prevent infinite loop#530
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughAdds cleanup for rejected promises from async validators so async validation promises are cleared on both resolve and reject, preventing infinite submit loops; adds a test ensuring submission does not hang when an async validator rejects and that validation reruns after a subsequent value change. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/FinalForm.submission.test.ts`:
- Line 1284: The variable callCountAfterChange is declared but never used;
remove the unused declaration to clean up the test. Locate the line that assigns
const callCountAfterChange = validationCallCount (and any immediate unused
references to callCountAfterChange) and delete that statement so the test relies
directly on validationCallCount or existing assertions instead of the dead
variable.
…nite loop - Added .catch() handler to clear async validation promise when rejected - Prevents infinite submit loop when async validators return rejected promises - Test verifies promise is cleared and validation can run again
4bb6147 to
d0b0f64
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #530 +/- ##
==========================================
- Coverage 99.05% 98.75% -0.31%
==========================================
Files 13 13
Lines 849 882 +33
Branches 286 299 +13
==========================================
+ Hits 841 871 +30
- Misses 8 11 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
erikras-dinesh-agent
left a comment
There was a problem hiding this comment.
LGTM! ✅
Clean fix for #166. The .catch() handler correctly clears the async validation promise on rejection and re-throws, preventing the infinite loop. Test covers both the non-hanging behavior and fresh validation after subsequent changes. Bundle size limit bump is justified.
Approved — waiting for CodeRabbit re-review to clear the stale CHANGES_REQUESTED status.
erikras-dinesh-agent
left a comment
There was a problem hiding this comment.
Re-approving after CodeRabbit fixes. LGTM ✅
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
erikras-richard-agent
left a comment
There was a problem hiding this comment.
LGTM! Clean fix — adding .catch() to clear the async validation promise on rejection is the right approach. The test properly verifies both the error handling and that subsequent validations trigger fresh runs. ✅
|
What kind of Silicon Valley team wizardry is that)) 🧙♂️ 🔮 ✨ |
|
Published in |
Problem: When an async validator returns a rejected promise (instead of throwing), the form gets stuck in an infinite submit loop because the validation promise is never cleared from the
asyncValidationPromisesobject.Root Cause: The
.then()handler withclearAsyncValidationPromiseonly runs on successful resolution. When a promise rejects, the handler never executes, leaving the rejected promise in the tracking object. Each submit waits for this promise, catches the rejection, and recursively calls submit again - creating an infinite loop.Solution: Added a
.catch()handler that also callsclearAsyncValidationPromisebefore re-throwing the error. This ensures the promise is cleaned up regardless of whether it resolves or rejects.Testing:
Fixes #166
Summary by CodeRabbit
Bug Fixes
Tests