Fix #1050: useField returns Form initialValues on first render#1060
Fix #1050: useField returns Form initialValues on first render#1060
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughInitialization logic in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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/useField.ts`:
- Around line 116-125: The lookup for form initial values uses direct property
access (form.getState().initialValues?.[name]) which breaks for path-style names
like "user.name" or "items[0].id"; change it to use Final Form's path-aware
getter (getIn) on the form state initialValues when computing formInitialValue
so formInitialValue = getIn(form.getState().initialValues, name) (falling back
to existing initialValue and preserving the existing select/multiple -> []
handling for initialStateValue). Ensure you import/use the same getIn utility
used elsewhere in the repo and keep references to name, initialValue,
initialStateValue unchanged.
65f0e9b to
dccbeb6
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Issue: In v7.0.0, useField returns undefined on first render even when Form initialValues are set. This breaks apps trying to upgrade from v6. Root cause: useField's useState initializer falls back to creating initial state when getFieldState() returns undefined, but only checks field-level initialValue, not the Form's initialValues. Solution: In the fallback case, use getIn() to read form.getState().initialValues for the field name before using field-level initialValue. This correctly handles nested field paths like 'user.name' or 'items[0].id'. Form-level initialValues take precedence. Tests: - useField returns Form initialValues on first render - useField uses field initialValue when Form initialValues missing that field - useField handles nested field paths (user.name) - useField handles array field paths (items[0].name) - All existing tests pass (16/16) This is a clean solution that avoids the side effects of synchronous registration during render (which React forbids).
dccbeb6 to
825ff04
Compare
Issue: In v7.0.0, useField returns undefined on first render even when Form initialValues are set. This breaks apps trying to upgrade from v6.
Root cause: useField's useState initializer falls back to creating initial state when getFieldState() returns undefined, but only checks field-level initialValue, not the Form's initialValues.
Solution: In the fallback case, check form.getState().initialValues[name] before using field-level initialValue. Form-level initialValues take precedence.
Tests:
This is a clean solution that avoids the side effects of synchronous registration during render (which React forbids).
Closes #1050
Summary by CodeRabbit
Tests
Bug Fixes