Graph root is not a containing block for absolutely positioned layers

Đang mở
#414 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #425 của @draedful — đã merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
playwright, react, typescript
Lĩnh vực
frontend, testing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
TypeScript
Star
145
Fork
12
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
43

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của gravity-ui/graph

Tất cả issue của gravity-ui/graph

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.