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

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
Contributor

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 — September 17, 2026

Rebased onto current master (c241125); signed/GitHub-Verified head: 4bef1200164cd7bc98d9743248dffd9ec5abf306.

  • Full suite: 30 suites, 197 tests passed; 1 test skipped.
  • TypeScript, ESM/CJS/declaration build, focused ESLint (0 errors), Prettier and diff checks passed.
  • GitHub signatures and changed-file blobs were checked against the local branch.
  • Includes upstream fix: resolve pre-existing test failures on master #815, which fixes the prior pickAttrs and React-17 fallback test failures.
  • Upstream CI: ✅ test currently action_required. A maintainer must approve the fork workflow before it can run.
  • Vercel preview still requires upstream team authorization.

AI assistance disclosure

Codex assisted with implementation, conflict resolution, regression tests, and validation.

Summary by CodeRabbit

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

@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 StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: ce63bb34-9e4c-429d-bc7e-c15a421df58c

📥 Commits

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

📒 Files selected for processing (1)
  • tests/utils.test.ts

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


Walkthrough

删除未定义的嵌套属性时,internalSet 先复制目标对象或数组,再删除属性并写回。测试验证源对象保持不变。React 事件测试收窄了类型提取范围。

Changes

嵌套属性不可变删除

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

React 事件属性测试

Layer / File(s) Summary
收窄事件处理器提取范围
tests/utils.test.ts
测试仅从 DOMAttributes 提取事件处理器名称,要求至少检测到一个事件处理器,并验证这些事件不会被 pickAttrs 丢弃。

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: yoyo837

Merge Risk: ⚪ Minimal · up to 4bef1

The change is narrowly scoped and no concrete correctness, availability, security, or data-integrity risk remains identified.

🚥 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
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:删除嵌套值时保留源对象。标题简洁、清晰,并与代码和测试变更一致。
  • 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.

@yoyo837

yoyo837 commented Sep 17, 2026

Copy link
Copy Markdown
Member

Rebase please.

@nrps9909
nrps9909 force-pushed the codex/preserve-set-source branch from 29a9884 to 4bef120 Compare September 17, 2026 08:17
@nrps9909

Copy link
Copy Markdown
Contributor Author

Rebased onto current master (c241125); signed/GitHub-Verified head: 4bef1200164cd7bc98d9743248dffd9ec5abf306.

  • Full suite: 30 suites, 197 tests passed; 1 test skipped.
  • TypeScript, ESM/CJS/declaration build, focused ESLint (0 errors), Prettier and diff checks passed.
  • GitHub signatures and changed-file blobs were checked against the local branch.
  • Includes upstream fix: resolve pre-existing test failures on master #815, which fixes the prior pickAttrs and React-17 fallback test failures.
  • Upstream CI: ✅ test currently action_required. A maintainer must approve the fork workflow before it can run.
  • Vercel preview still requires upstream team authorization.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.80%. Comparing base (c241125) to head (4bef120).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #807      +/-   ##
==========================================
+ Coverage   86.77%   86.80%   +0.03%     
==========================================
  Files          41       41              
  Lines        1096     1099       +3     
  Branches      397      383      -14     
==========================================
+ Hits          951      954       +3     
  Misses        143      143              
  Partials        2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yoyo837

yoyo837 commented Sep 17, 2026

Copy link
Copy Markdown
Member

Non-blocking edge case: if the parent path value is a truthy primitive (e.g. set({ keep: 'str' }, ['keep', 'light'], undefined, true)), the new { ...origin } spread turns the string into a char-indexed object, whereas the old code was a no-op. The get guard in set() filters null/undefined but not truthy primitives. Unlikely in practice since parents are objects/arrays, but a typeof origin === 'object' check before copying would make it airtight.

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.

2 participants