fix(form-core): apply async defaultValues to untouched fields after other fields are edited#2246
Open
xianjianlf2 wants to merge 1 commit into
Open
Conversation
…dits FormApi.update() gated the whole defaultValues merge on the form-level `isTouched` flag, which is true as soon as any single field is edited. As a result, once the user touched one field, asynchronously-arriving default values were no longer applied to *any* field, leaving untouched fields empty. Drop the form-level gate and instead preserve values per-field: edited (touched) fields keep the user's input, while untouched fields — including ones that have not mounted yet — receive their newly-arrived defaults. Closes TanStack#2229
📝 WalkthroughWalkthrough
ChangesAsync default value updates
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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. Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🎯 Changes
Fixes #2229.
FormApi.update()previously gated default-value merging on the form-level touched state, so touching one field prevented asynchronously arriving defaults from applying to every other untouched field.✅ Checklist
🚀 Release Impact
Notes
The existing behavior of not wiping an edited field during update is preserved. The new behavior only applies newly arrived defaults to fields that are still untouched.