fix(react-form): Make form.options reactive by adding getter#2044
fix(react-form): Make form.options reactive by adding getter#2044swushi wants to merge 3 commits into
Conversation
|
Fixes an issue where form.options.defaultValues was not reactive when initializing a form with async data. The options object was captured in the useMemo closure and never updated when formApi.options changed. Adding a getter for options (similar to the existing state getter) ensures that the latest options are always returned, fixing reactivity issues when comparing current values to defaultValues.
9fc39cc to
29a65ed
Compare
|
View your CI Pipeline Execution ↗ for commit 84f08fa
☁️ Nx Cloud last updated this comment at |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2044 +/- ##
===========================================
- Coverage 90.35% 57.20% -33.16%
===========================================
Files 38 18 -20
Lines 1752 250 -1502
Branches 444 47 -397
===========================================
- Hits 1583 143 -1440
+ Misses 149 92 -57
+ Partials 20 15 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@swushi this look good! Can you add a test in either |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
Summary
Fixes an issue where
form.options.defaultValueswas not reactive when initializing a form with async data.Problem
When using
useForm()with async data:Root Cause
The
optionsobject was captured in theuseMemoclosure and never updated whenformApi.optionschanged, even thoughformApi.update()was called in the effect lifecycle.Solution
Added a getter for
options(similar to the existingstategetter) to ensure the latest options are always returned:This follows the same pattern as the
stategetter, as mentioned in the existing comment: "We must add allgetters fromcore'sFormApihere, as otherwise the spread operator won't catch those"Related Discussion
https://canary.discord.com/channels/719702312431386674/1471891391348215972