Graph root is not a containing block for absolutely positioned layers

オープン
#414 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

関連するプルリクエストがすでにマージされています。

  • #425 @draedful による — マージ済み

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
playwright, react, typescript
領域
frontend, testing

調査の方向性

Start with packages/graph/src/services/Layer.css, Graph.attach(root), and packages/graph-react/src/graph-canvas.css to trace how the root and layers are positioned. Then inspect the contract apps and the linked pull request #425; the acceptance criteria call for a vanilla graph E2E test with a padded, bordered root, unchanged React behavior, and an intentional decision about the contract workarounds and migration docs.

索引モデルが issue の本文から書いたものです。

説明

Problem

Core layers are absolutely positioned (packages/graph/src/services/Layer.css: .layer { position: absolute; inset: 0; width: 100%; height: 100% }), but neither Graph.attach(root) nor the core stylesheet makes the root a containing block, and the docs do not say the root must be positioned. Only the React wrapper does it (packages/graph-react/src/graph-canvas.css: position: relative).

In a vanilla app whose root is not positioned, the layers are laid out against the nearest positioned ancestor or the viewport, not against the root:

  • the canvas covers the page (observed 0,0 1280×720 for a root at 24,24 902×652);
  • pointer hit-testing uses canvas-relative coordinates (Graph.getPointInCameraSpace → getXY(canvas, event)), while the camera's wheel zoom (Camera.ts) and code that maps world points to the root (cameraService.getAbsoluteXY + root rect, used by @gravity-ui/graph-playwright) use the root's box. Clicks land ~25px off. Large blocks absorb the error; thin connections are missed.

The package-contract apps work around it with style="position: relative" on #graph (packages/graph-devtools/contract/app/index.html, packages/graph-playwright/contract/app/index.html); the shared scripts/package-contract/shared/base.css does not set it.

Proposal

Pick one and document it:

  1. Core makes the root a containing block, e.g. a .graph-root { position: relative } class added by attach() (and removed on detach), or an inline style only when the computed position is static. Consumers' own positioning keeps working.
  2. Or document the requirement in the core README / getting-started docs and warn in development when the attached root has position: static.

Option 1 is preferred: it matches what GraphCanvas already does and removes a silent misalignment.

Acceptance criteria

  • A vanilla graph attached to a non-positioned root renders inside the root and hit-tests correctly (E2E: root with padding/border, click a connection via GraphConnectionPO.click()).
  • React GraphCanvas behaviour is unchanged.
  • The position: relative workarounds in contract apps are removed or kept intentionally; docs and the v1→v2 migration guide mention the change if behaviour changes.

Found while adding the graph-playwright package contract in #406.

🤖 Drafted with Claude Code

主要言語
TypeScript
スター
145
フォーク
12
平均マージ
1日 14時間
マージ済み PR(30日)
43

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

gravity-ui/graph のほかの issue

gravity-ui/graph の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。