antvis / antvis/X6

当开启允许嵌套组件后,node.addChild() 这个函数将不生效

Open
#4,141 2 comments 0 reactions 0 assignees View on GitHub
type: bug 缺陷
Dominant language
TypeScript
Stars
6.7k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

### 问题描述

我通过 `node:added` 事件,在创建节点后为其添加一个父节点的群组功能,我发现当我拖拽父节点时,子节点没有随着移动,通过打log发现,node.addChild() 之后的日志发现节点是存在父子关系的,但是在拖拽节点时打印日志发现,父节点没有关联到子节点。
该问题只在以下配置开启时生效
```ts
new Graph({
// 允许组件嵌入组件
embedding: {
enabled: true,
},
});
···

### 重现链接

https://codesandbox.io/p/sandbox/modest-morning-k9f8jc?layout=%257B%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clr5qy05x0006356hccnlmx1c%2522%252C%2522sizes%2522%253A%255B100%252C0%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clr5qy05x0002356hnio4il00%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clr5qy05x0003356h6r9a9hy7%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clr5qy05x0005356hx2tlizqw%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clr5qy05x0002356hnio4il00%2522%253A%257B%2522id%2522%253A%2522clr5qy05x0002356hnio4il00%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clr5qy05x0005356hx2tlizqw%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clr5qy05x0004356hisnqukqa%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522UNASSIGNED_PORT%2522%252C%2522port%2522%253A0%252C%2522path%2522%253A%2522%252F%2522%257D%255D%252C%2522id%2522%253A%2522clr5qy05x0005356hx2tlizqw%2522%252C%2522activeTabId%2522%253A%2522clr5qy05x0004356hisnqukqa%2522%257D%252C%2522clr5qy05x0003356h6r9a9hy7%2522%253A%257B%2522tabs%2522%253A%255B%255D%252C%2522id%2522%253A%2522clr5qy05x0003356h6r9a9hy7%2522%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Afalse%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D

### 重现步骤

1. 进入页面
2. 拖拽 Rect 组件到右侧
3. 这时拖拽父组件 Parent 发现子组件没有跟随
4. 将子组件拖入父组件后,拖拽父组件,子组件跟随

### 预期行为

我的预期是 当我使用 node.addChild() 后它就应该存在父子关系,而实际是必须是拖入后才存在

### 平台

- 操作系统: [Windows]
- 网页浏览器: [Google Chrome,]
- X6 版本: [2.16.1]

### 屏幕截图或视频(可选)

_No response_

### 补充说明(可选)

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the linked CodeSandbox with embedding.enabled and the node:added handler that calls node.addChild(). Start by tracing node.addChild() and the embedding drag behavior, then verify that dragging the parent moves the programmatically attached child without manually dropping it into the parent; add regression coverage if the repository’s test structure identifies a suitable location.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.