[v2] Connection endpoints: colliding derived ids and no public endpoint/port-owner API
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- typescript
调研方向
Start with packages/graph/src/store/connection/ConnectionState.ts and ConnectionList.getOrCreateConnection to trace derived IDs and connection reuse. Then inspect the port and connection store APIs and their tests. Done means adding documented, tested endpoint and port-owner APIs and deterministic IDs that distinguish anchor connections across blocks and keep port-only IDs stable; the acceptance criteria also call for follow-up package limitations to be lifted.
由索引模型根据 Issue 内容生成。
描述
Problem
TConnection has two addressing modes:
- Block-based:
sourceBlockId/targetBlockId, optionallysourceAnchorId/targetAnchorId. Core resolves these to ports:"<blockId>_output"/"<blockId>_input"for block points,"<blockId>/<anchorId>"for anchors. - Port-based:
sourcePortId/targetPortId.
Core has two gaps around these modes. Because of them, the extracted packages (#396) cannot treat both modes the same way.
1. Derived connection ids collide
ConnectionState.getConnectionId (packages/graph/src/store/connection/ConnectionState.ts, getConnectionId) builds the id of a connection that has no explicit id:
if (hasId(connection.sourceAnchorId) && hasId(connection.targetAnchorId)) {
return [connection.sourceAnchorId, connection.targetAnchorId].join(":"); // no block ids
}
return [connection.sourceBlockId, connection.targetBlockId].join(":");
ConnectionList.getOrCreateConnection then reuses whatever state already has that id and calls updateConnection on it.
- Anchor connections: two connections between different blocks that use the same anchor names get the same id (
"out:in"). The second one rewires the first instead of creating a new connection. This happens routinely after duplicating blocks (#408 had to give every copy an explicit id to avoid it). - Parallel block connections: they collapse into one (
"a:b"). - Port-only connections: they get a random id, so they cannot be addressed deterministically.
2. No public API to resolve endpoints
Given a ConnectionState or a PortState, there is no public, serializable way to get:
- the resolved source and target port ids together with the owning block id and anchor id, regardless of which mode the connection was declared in;
- the block that owns a port.
PortState.owner/componentis a view component, not store data, and it is absent until the view exists. - a connection by its endpoints (store lookup).
Impact
@gravity-ui/graph-layered,@gravity-ui/graph-elk: port-only connections are skipped and documented as unsupported, because there is no port → block resolution. Anchor endpoints are not taken into account in layout.@gravity-ui/graph-duplicate-block: port-based connections are copied only when the port id can be derived from block or anchor ids, and copies need explicit ids (see 1).@gravity-ui/graph-connection-editing: decides between block and port mode by comparing port ids withcreateBlockPointPortId/createAnchorPortId, and dedupes custom-port connections by scanning$connectionsMap.@gravity-ui/graph-playwright: cannot find connections by endpoints or reliably tell apart connections between the same blocks on different anchors. Related: #409.
Proposal (to be refined)
- Deterministic derived ids that include block ids for anchor connections, e.g.
"<sourceBlockId>/<sourceAnchorId>:<targetBlockId>/<targetAnchorId>", and that are stable for port-based connections, e.g. built from the port ids. This is a breaking change for consumers that rely on today's derived ids; it needs a migration note. ConnectionState.getEndpoints(): a serializable{ source: { portId, blockId?, anchorId? }, target: { … } }, available without the view.- Port owner as store data: a public port → owner block/anchor helper, e.g.
connectionsList.getPortOwner(portId)or owner info onPortState. connectionsList.findByEndpoints(...), accepting either mode.
Acceptance criteria
- Unit tests:
- two anchor connections with the same anchor names on different blocks stay distinct;
- parallel connections behave as documented;
- port-only connections get a stable id.
- The endpoint and owner APIs work for block, anchor and custom ports, are covered by tests for each mode separately, and are documented.
- Follow-ups listed for the packages above: lift the documented port-only limitations where the new API makes it possible.
- 主要语言
- TypeScript
- 星标
- 145
- 派生
- 12
- 平均合并
- 1 天 14 小时
- 30 天内合并 PR
- 43
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
gravity-ui/graph 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
gravity-ui/graph#457 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
gravity-ui/graph#455 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
gravity-ui/graph#456 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
gravity-ui/graph#431 ·
维护者通常 1 天内回复
-
Graph root is not a containing block for absolutely positioned layers可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 4/5 3-5 天 新手友好度 25/100
gravity-ui/graph#414 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
tintinweb/pi-subagents#459 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
danielmiessler/LifeOS#2830 ·
维护者通常 6 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
freshframework/fresh#3920 ·
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
area: client enhancement priority: low
难度 2/5 1-3 小时 新手友好度 75/100
opensro-dev/opensro#3681 ·
维护者通常 1 天内回复