Skip to content

Form.Item 的 name 为数组时 且 preserve=false,shouldUpdate 有具体判断时,有问题 #59044

Open

Description

@linxianxi

Reproduction link

Edit on CodeSandbox

Steps to reproduce

字段 a 选择 2

What is expected?

字段 b 和字段 c 都消失

What is actually happening?

字段 b 消失,但是字段 c 还在

Environment Info
antd 6.6.1
React latest
System mac
Browser chrome

Activity

  1. QDyanbing commented on Aug 19, 2026

    @QDyanbing
    Member
    Image

    我操作有问题还是改过demo?

  2. QDyanbing commented on Aug 19, 2026

    @QDyanbing
    Member

    #59043 是在说一个问题吗?

  3. linxianxi commented on Aug 19, 2026

    @linxianxi
    ContributorAuthor

    #59043 是在说一个问题吗?

    看上去不像是一个问题

  4. linxianxi commented on Aug 19, 2026

    @linxianxi
    ContributorAuthor
    Image 我操作有问题还是改过demo?

    你这就是有问题的

  5. ZQDesigned commented on Aug 19, 2026

    @ZQDesigned
    Contributor

    @QDyanbing 我简单验证了一下,确实不是相同问题,现象都是切换后 b 消失了,但 c 还留着。

    总结下根因:

    • #59043:核心是 preserve={false} 和 initialValues 的交互问题。字段卸载时,store 没有直接清掉,而是回退到了 initialValues,所以 b 虽然卸载了,但值还在,导致依赖 b 的 c 继续显示。

    • #59044:核心是字段卸载时,依赖字段的 shouldUpdate(predicate) 没有正确触发重渲染。b 被移除后,c 外层这层 shouldUpdate 没命中更新,所以旧的渲染结果被保留下来了。把 shouldUpdate 改成 true 后正常,也是因为它会强制重渲染。

  6. added
    🐛 BugAnt Design Team had proved that this is a bug.
    and removed on Aug 19, 2026
  7. nrps9909 commented on Aug 27, 2026

    @nrps9909
    Contributor

    I reproduced this against current @rc-component/form master with the original nested paths and traced it to the shared @rc-component/util setter rather than Ant Design's Form wrapper.

    When preserve={false} unregisters ['a', 'b'], the removeIfUndefined branch clones the root store but deletes from the still-shared nested a object. That mutates prevStore.a, so the next render-prop predicate receives prev.a?.b === next.a?.b === undefined and does not refresh c.

    I opened react-component/util#807 with a focused immutable-delete fix and source/reference regression coverage. Cross-package verification with the exact nested A → B → C reproduction:

    • released/current util: password2 remains rendered (regression fails)
    • PR Fix wrong description in Tree props table #807 local build: the same field-form test passes
    • full util suite: 29 suites passed, 182 tests passed, 1 skipped
    • TypeScript, ESLint, Prettier, ESM/CJS build, and diff checks passed

    Once that util fix is merged and released, this Ant Design reproduction should be resolved without a Form-specific workaround.

    AI assistance disclosure: Codex was used to inspect the original sandbox, trace the shared-reference mutation, construct the cross-package regression, and run the checks. The behavior and results were verified locally.

  8. github-actions commented on Sep 11, 2026

    @github-actions
    Contributor

    @ZQDesigned 这个 issue 已经超过 14 天没有更新或关联 PR。如果您仍在处理这个 issue,请更新进度;如果您无法继续处理,请联系维护者重新分配。

    This issue has been inactive for more than 14 days without any updates or linked PR. If you are still working on this issue, please provide a progress update. If you are unable to continue, please contact the maintainers for reassignment.

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

Metadata

Metadata

Assignees

Labels

Inactive🐛 BugAnt Design Team had proved that this is a bug.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions