Skip to content

fix: removeCells on parent node leaves orphan children causing duplicates#5039

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-removecells-method
Open

fix: removeCells on parent node leaves orphan children causing duplicates#5039
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-removecells-method

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When removing a parent node via removeCells, its children are not recursively removed from the model, leaving orphan nodes. Subsequent re-creation of nodes with the same IDs results in apparent duplicates.

Root Cause

collection.removeCells sets cell.model = null (via the removed event → onCellRemoved) before calling cell.remove(). Inside remove(), eachChild() calls getChildren() which requires this.model to resolve child IDs — returning null when model is already null. Children are silently skipped.

Changes

  • src/model/cell.tsremove(): Fall back to _children cache when getChildren() returns null due to model being null, ensuring children are still recursively removed:
    const children = this.getChildren() ?? (this._children ? [...this._children] : null)
    if (children) {
      children.forEach((child) => child.remove(options))
    }
  • src/model/cell.tsremove(): Keep parent._children in sync when directly mutating parent.store (bypassing setChildren()), so the fallback cache is not stale.
  • __tests__/model/cell.spec.ts: Add test that simulates the actual collection.removeCells flow (model set to null before remove() is called) and asserts children are removed from the model.
Original prompt

This section details on the original issue you should resolve

<issue_title>🐞3.1.6、3.1.5的删除节点removeCells方法有问题(删除子节点以后,重新创建更新子节点,出现重复节点),3.1.4正常,麻烦排查一下</issue_title>
<issue_description>### 问题描述

🐞3.1.6、3.1.5的删除节点removeCells方法有问题(删除子节点以后,重新创建更新子节点,出现重复节点),3.1.4正常

重现链接

重现步骤

🐞3.1.6、3.1.5的删除节点removeCells方法有问题(删除子节点以后,重新创建更新子节点,出现重复节点),3.1.4正常

预期行为

删除节点后,重新创建子节点后,不会出现之前已经删除的节点

平台

谷歌浏览器、mac

屏幕截图或视频(可选但最好有)

No response

补充说明(可选)

No response</issue_description>

<agent_instructions>尝试下找出issue 中问题的原因,并修复。</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@GaoFuhong codesandbox 来个可复现 demo

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: hustcc <7856674+hustcc@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with removeCells method leading to duplicate nodes fix: removeCells on parent node leaves orphan children causing duplicates Feb 25, 2026
Copilot AI requested a review from hustcc February 25, 2026 04:54
@hustcc hustcc marked this pull request as ready for review February 25, 2026 05:12
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.39%. Comparing base (3697830) to head (56249f5).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5039      +/-   ##
==========================================
+ Coverage   83.38%   83.39%   +0.01%     
==========================================
  Files         332      332              
  Lines       38487    38498      +11     
  Branches     7898     7905       +7     
==========================================
+ Hits        32093    32107      +14     
+ Misses       6371     6368       -3     
  Partials       23       23              
Flag Coverage Δ
x6 83.39% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/model/cell.ts 75.40% <100.00%> (+0.46%) ⬆️
🚀 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.

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

Labels

None yet

Projects

None yet

3 participants