[WIP] Fix bug with incorrect errors for nested fields#271
Conversation
9ea1b69 to
ebd3318
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #271 +/- ##
========================================
Coverage ? 100.00%
========================================
Files ? 12
Lines ? 557
Branches ? 116
========================================
Hits ? 557
Misses ? 0
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I can confirm this bug also affects me. I didn't test your solution but it looks like it can solve this issue. |
erikras-richard-agent
left a comment
There was a problem hiding this comment.
Review by Richard (Team Lead)
WIP fix for incorrect errors with nested fields. Marked as experimental by the author. Will evaluate the approach but given WIP status, this is lower priority for merge consideration.
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
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. ✨ Finishing touches🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Comment |
|
Thank you for identifying this bug and the fix approach, @perrin4869! The bug you found still exists in the current TypeScript codebase. We'll be porting your fix ( Closing this PR since it targets the old Flow code, but the fix will be applied. 🙏 |
Fixes #271 Problem: When setIn tries to remove a nested field key from a parent that contains a string error message (e.g., 'Invalid range' on 'range' when removing 'range.min'), the destructuring operation converts the string to an object with numeric keys ({ '0': 'I', '1': 'n', ... }). This breaks nested field validation where a validator on a parent field (like 'range') returns a string error message, but child fields ('range.min', 'range.max') also exist. Root Cause: Line 61 in setIn.ts: `const { [key]: _removed, ...final } = current as any` When `current` is a string, JavaScript's destructuring coerces it to an object, treating each character as a numbered property. Solution: Added a `typeof current === 'string'` check before the destructure operation. Strings cannot have custom properties anyway, so we return the string as-is instead of trying to remove keys from it. Changes: - src/structure/setIn.ts: - Added string type check before destructuring (lines 61-64) - Return string unchanged when trying to remove properties - src/FinalForm.validating.test.ts: - Added test case for nested field-level validation errors - Verifies 'Invalid range' stays a string, not converted to object Impact: ✅ Nested field validators work correctly ✅ String error messages preserved on parent fields ✅ No breaking changes ✅ All existing tests pass
…527) Fixes #271 Problem: When setIn tries to remove a nested field key from a parent that contains a string error message (e.g., 'Invalid range' on 'range' when removing 'range.min'), the destructuring operation converts the string to an object with numeric keys ({ '0': 'I', '1': 'n', ... }). This breaks nested field validation where a validator on a parent field (like 'range') returns a string error message, but child fields ('range.min', 'range.max') also exist. Root Cause: Line 61 in setIn.ts: `const { [key]: _removed, ...final } = current as any` When `current` is a string, JavaScript's destructuring coerces it to an object, treating each character as a numbered property. Solution: Added a `typeof current === 'string'` check before the destructure operation. Strings cannot have custom properties anyway, so we return the string as-is instead of trying to remove keys from it. Changes: - src/structure/setIn.ts: - Added string type check before destructuring (lines 61-64) - Return string unchanged when trying to remove properties - src/FinalForm.validating.test.ts: - Added test case for nested field-level validation errors - Verifies 'Invalid range' stays a string, not converted to object Impact: ✅ Nested field validators work correctly ✅ String error messages preserved on parent fields ✅ No breaking changes ✅ All existing tests pass Co-authored-by: Erik Rasmussen <[email protected]>
This is a work in progress, but I would appreciate your input.
This PR targets a bug where you put a validator on the root of a nested field. Let's say you want to ensure a range is valid. Assert that
range.min < range.maxby setting a validator onrange. This is required, if for example, you have an array of ranges (as in our case).The error message gets converted to an object with keys.
This PR introduces a failing test, if you have any preference on how to fix this issue, please tell me. Otherwise I can come up with a solution.
As an aside, focusing on nested fields can cause weird edge-cases too, but that's a task for a separate PR :)
Thanks!