Graph root is not a containing block for absolutely positioned layers

Aperta
#414 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #425 di @draedful — integrata

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
playwright, react, typescript
Ambito
frontend, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
TypeScript
Stelle
145
Fork
12
Merge medio
1g 14h
PR unite (30g)
43

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di gravity-ui/graph

Tutte le issue di gravity-ui/graph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.