Skip to content

fix: preserve source when removing nested values - #807

Open
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/preserve-set-source
Open

fix: preserve source when removing nested values#807
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/preserve-set-source

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 26, 2026

Copy link
Copy Markdown

Summary

  • clone the nested container before removeIfUndefined deletes its leaf
  • preserve the input object and a new reference along the changed path
  • add a regression assertion for both immutability and child identity

Why

internalSet cloned the root, but the deletion branch still mutated the original nested container through the shared clone[path] reference. Consumers that compare previous and next nested values can consequently miss the removal. This is the underlying cause reproduced from ant-design/ant-design#59044.

Verification

  • exact regression failed on current master: the source object lost its nested light property
  • full test suite: 29 suites passed, 182 tests passed, 1 skipped
  • cross-package rc-field-form preserve suite: 13/13 passed with this local build; the added reproduction fails with the released util
  • tsc --noEmit
  • ESLint (0 errors; 6 existing unused-disable warnings)
  • Prettier check
  • father build
  • git diff --check

AI assistance disclosure: Codex was used to trace the mutation, reproduce the downstream behavior, implement the focused fix, and run the checks above. All behavior and results were verified locally.

Summary by CodeRabbit

  • Bug 修复
    • 修复删除嵌套属性时可能直接修改原对象的问题。
    • 现在会返回更新后的新对象,同时保留原对象及其嵌套数据不变。
    • 支持对象和数组中的嵌套属性安全删除。
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 259eeb0f-fcaf-4caa-8437-3b48344c0cdc

📥 Commits

Reviewing files that changed from the base of the PR and between d1045f4 and 29a9884.

📒 Files selected for processing (2)
  • src/utils/set.ts
  • tests/utils.test.ts

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


Walkthrough

删除未定义的嵌套属性时,internalSet 先复制目标对象或数组,再删除属性并写回。测试验证源对象不变,且返回对象使用新的嵌套引用。

Changes

嵌套属性不可变删除

Layer / File(s) Summary
复制嵌套值并验证不可变更新
src/utils/set.ts, tests/utils.test.ts
internalSet 在删除属性前复制嵌套对象或数组。测试验证源对象保持不变,并确认返回对象中的嵌套对��不是源对象引用。

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

Merge Risk: ⚪ Minimal · up to 29a98

This localized change preserves the source object and nested child identity when removing undefined values, with regression coverage and standard checks passing; no actionable merge-blocking risk remains.

Poem

小兔看见副本先生成

嵌套属性随后安静消失
源对象仍保持原样
新对象承载新的引用
胡萝卜为不可变更新鼓掌

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:删除嵌套值时保留源对象。标题简洁、明确,并与代码和测试变更一致。
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

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

Labels

None yet

1 participant