| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…ent update() Track the last component-provided defaultValues in a private _componentDefaultValues field. In update(), compare incoming defaultValues against that snapshot rather than against oldOptions.defaultValues (which reset() mutates). An unchanged re-render now leaves the post-reset values intact, and the restoration block preserves the runtime baseline so no-arg reset() continues to use the post-submit value.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 480d78a8-4036-454b-9bb7-2c6c691b1254 📥 CommitsReviewing files that changed from the base of the PR and between 512626e and 99028bb. 📒 Files selected for processing (1)
📝 Walkthrough WalkthroughAdds a private _componentDefaultValues field to FormApi to separately track component-provided defaultValues. The update() method is modified to detect when component defaults are unchanged and restore runtime defaultValues (set by reset(newValues)) instead of overwriting them. Two regression tests and a patch changeset are included. ChangesFix reset(newValues) overwrite by update()
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem🚥 Pre-merge checks | ✅ 5 ✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agentsVerify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@packages/form-core/src/FormApi.ts`: - Around line 1764-1768: The shouldUpdateValues logic in FormApi.ts uses a truthiness check for options.defaultValues, which incorrectly skips legitimate falsy default values like 0, empty string, false, and null. Replace the truthiness check (options.defaultValues &&) with an explicit presence check such as checking if the property is not undefined or exists in the options object, so that falsy defaults will be properly evaluated and applied when the form is untouched.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cb898de9-f728-4db9-8d6a-eb38fbdc581e
📥 CommitsReviewing files that changed from the base of the PR and between 6a73479 and 512626e.
📒 Files selected for processing (3)
Sorry, something went wrong.
options.defaultValues && is a truthiness gate that incorrectly skips falsy-but-valid defaults (e.g. a field whose value is 0, false, or ''). Use !== undefined to match the existing guard pattern in the same block.
| Back | FazBrowse Home | New Git URL |
Fixes #1681
Thanks for the detailed repro. It made this much easier to pin down.
Problem
If you call form.reset(newValues) inside onSubmit and your framework re-renders the component immediately after, the reset values get silently overwritten.
reset(newValues) writes the new values into this.options.defaultValues. When the adapter calls update() on re-render with the same props it had before, update() compares the incoming defaultValues against oldOptions.defaultValues (which now holds the reset values rather than the original component defaults), sees a delta that isn't really a change, sets shouldUpdateValues = true, and reverts the form back to the original defaults.
There's a second issue: this.options = options runs on every re-render, replacing the whole options object. After a reset(), the runtime defaultValues is gone. A later no-arg reset() uses the stale component default instead of the post-submit baseline.
Fix
The root problem is that update() has no way to tell "the component's defaultValues prop actually changed" apart from "someone called reset() and now defaultValues looks different." This adds a private _componentDefaultValues field that tracks what the adapter last explicitly provided, separate from the runtime this.options.defaultValues that reset() writes to.
In update():
The constructor guard (oldOptions.defaultValues !== undefined) keeps the restoration block from firing on the very first update() call, where oldOptions is the empty class default {}. Initial form values come from baseStoreVal before that first call, so the guard is safe.
Tests
Two regression tests in FormApi.spec.ts:
Summary by CodeRabbit