fix(form-core): shift the array's own index when shifting nested array meta - #2361
fix(form-core): shift the array's own index when shifting nested array meta#2361dfedoryshchev wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe form core now preserves nested-array metadata indices during move, remove, and insert operations. New tests verify blurred metadata and array values after nested insert and remove actions. A patch changeset documents the fix. ChangesNested array metadata shifting
Merge Risk: ⚪ Minimal · up to This localized fix corrects nested-array field metadata shifting and includes regression coverage; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Description checkExplanation The description clearly explains the defect, root cause, fix, affected helpers, branch scope, regression tests, and validation results. The checklist boxes are not marked, but the required testing and changeset information is otherwise documented. Full details: Docstring CoverageExplanation Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 2 files. (1 skipped: 1 unsupported.)
✨ 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 |
Changes
Inserting into or removing from an array nested inside another array wipes the following rows' field meta instead of shifting it. A flat array behaves correctly, so the two disagree.
updateIndex(metaHelper.ts:227) rewrites the first bracketed index it finds:fieldKey.replace(/\[(\d+)\]/, ...). Forusers[1].namethat is the right one. Forteams[0].members[1]it rewritesteams's index, producingteams[1].members[1]- a key that does not exist - so the read returnsundefinedand the shifted row is reset to default meta. Touched, blurred, dirty and errors are all lost.The fix anchors the rewrite on the array being mutated, so only the index directly after
${field}[moves.handleArraySwapalready does exactly this viagetFieldPath(field, index)(metaHelper.ts:147), so this brings the other three helpers into line with it rather than introducing a new approach.It reaches users through
removeFieldValue,insertFieldValueandmoveFieldValues;getAffectedFieldsnarrows it to array paths that themselves contain an index, which is why only the nested case is affected.Targeting
maindeliberately: onalphathe array subsystem was rewritten to a trie andupdateIndexno longer exists, so this is v1-only.Two regression tests next to the existing flat-array meta-shift tests.
form-coreis 507 passing with no type errors, eslint and prettier clean.Summary by CodeRabbit
Bug Fixes
Tests