Skip to content

fix: clean non-preserved list field by its current name - #815

Open
SudeepGowda55 wants to merge 1 commit into
react-component:masterfrom
SudeepGowda55:fix/preserve-list-index-change
Open

SudeepGowda55 wants to merge 1 commit into
react-component:masterfrom
SudeepGowda55:fix/preserve-list-index-change

Conversation

@SudeepGowda55

@SudeepGowda55 SudeepGowda55 commented Nov 14, 2026 •

Copy link
Copy Markdown

close #814

The unregister callback cleaned the store using the name path captured at register time. After List.remove/move shifts a mounted field to another index, unmounting it with preserve={false} targeted the old path, so its value stayed in the store and came back on remount. The callback now reads the field's current name path.

Test: added a preserve case (remove the first row, then unmount the surviving row's preserve={false} field) that fails before and passes after. Full suite passes.

Summary by CodeRabbit

  • 问题修复
    • 修复列表字段变更顺序后,清理操作可能使用旧字段路径的问题。
    • 调整字段隐藏且不保留值时的清理行为,确保表单仅保留预期字段值。

@vercel

vercel Bot commented Nov 14, 2026

Copy link
Copy Markdown

@SudeepGowda55 is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

字段注销回调现在会重新读取字段的当前名称路径。新增回归测试覆盖列表移除首项后卸载 preserve={false} 字段的情况。

Changes

保留值清理

层 / 文件 摘要
注销路径与回归覆盖
src/hooks/useForm.ts, tests/preserve.test.tsx
注销回调在清理前重新读取字段的 namePath。测试验证移除首项后,卸载 preserve={false} 的 memo 字段时,表单值只保留剩余项的 id。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to a0930

This fixes cleanup of non-preserved list field values after their index shifts. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题 “fix: clean non-preserved list field by its current name” 与变更内容一致。变更让 registerField 返回的注销回调在清理前读取字段当前的 namePath。新增测试覆盖列表删除首项后,非保留字段卸载时的值清理。标题准确说明了主要修复点:按当前名称清理非保留的列表字段。
Linked Issues check Passed [#814] 的核心需求是:字段因 List.move 或 List.remove 改变索引后,若以 preserve={false} 卸载,其值必须从 store 中清除。PR 将注销回调改为在清理前读取字段当前的 namePath(src/hooks/useForm.ts,+2 行)。注销时使用当前路径,可清除正确的 store 值,并避免使用注册时的旧路径。PR 也新增 tests/pres…
Out of Scope Changes check Passed PR 的改动集中在 registerField 注销回调的一处路径读取,以及 preserve 相关的一个回归测试。两者都直接服务于 #814 的 preserve={false} 在索引变化后残留值的问题,未发现无关改动。摘要中未列出其他源码或公共 API 声明变更。证据限制:未能直接核对 useForm.ts 的改动行,结论基于 AI 生成摘要与测试描述。
Full details: Linked Issues check

Explanation

[#814] 的核心需求是:字段因 List.move 或 List.remove 改变索引后,若以 preserve={false} 卸载,其值必须从 store 中清除。PR 将注销回调改为在清理前读取字段当前的 namePath(src/hooks/useForm.ts,+2 行)。注销时使用当前路径,可清除正确的 store 值,并避免使用注册时的旧路径。PR 也新增 tests/preserve.test.tsx 中的 'clean value by current name after index changed' 用例:删除首行后卸载保留项的 memo 字段,并断言完整表单值只保留 id。该用例对应 #814 的删除场景。证据限制:useForm.ts 的 diff 无法读取,文件读取在 registerField 之前被截断,因此改动行未被直接核对,判断基于 PR 摘要和测试描述。#814 中的移动(move)场景没有专门测试,但同一修复基于当前路径,理论上同样覆盖该场景。

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

我是兔子,轻敲键盘,
路径更新,旧值退场。
列表少了一行,
剩余字段仍有其名。
memo 隐去,值也清爽,
我蹦过绿草,庆祝收工!

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 299b0112-31cb-479d-921b-64311501654e
Commits

Reviewing files that changed from the base of the PR and between be0cc09 and a093028.

Files selected for processing: 2

  • src/hooks/useForm.ts
  • tests/preserve.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

List nested fields with preserve={false} retain values after move/remove changes their index

1 participant