Repository navigation
fix(graph): make the graph root a containing block for layers (#414) - #425
Merged
Merged
Conversation
Graph.attach() adds a `graph-root` class to the root and a full detach
removes it. Core styles declare `:where(.graph-root) { position: relative }`,
so a static root contains the absolutely positioned layers while any
position set by the application still wins.
Removes the `position: relative` workarounds from package-contract apps,
adds unit and E2E coverage, and documents the change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up: the unlayered :where() rule beat application styles declared in cascade layers (e.g. Tailwind v4 utilities). Move the rule into the `gravity-graph` layer, track which graphs mark a root so the class stays while another graph uses it and is never removed when the application set it, export GRAPH_ROOT_CLASS_NAME, and document the layer order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reviewer's GuideGraph attachment now marks its root with an exported File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
|
Preview is ready. |
3 tasks
Add the class on attach and remove it on full detach, like the instance bridge, instead of tracking graphs per root: a root hosts one graph. Declare the root rule in the package's styles.css entry instead of Layer.css, since it styles the graph root rather than a layer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #414
Problem
Core layers are
.layer { position: absolute; inset: 0 }, butGraph.attach(root)did not make the root positioned; only the ReactGraphCanvaswrapper did. In a vanilla app with astaticroot the layers were laid out against an outer positioned ancestor or the viewport: the canvas covered the page, and pointer hit-testing (canvas-relative) disagreed with the camera andgraph-playwright(root-relative), so clicks landed ~25px off. Package-contract apps worked around it withstyle="position: relative"on#graph.Fix
Option 1 from the issue, done so that the application's own positioning is never overridden:
Graph.attach(root)adds thegraph-rootclass (exported asGRAPH_ROOT_CLASS_NAME); a full detach (detach(),unmount(), moving to another root) removes it.@layer gravity-graph { :where(.graph-root) { position: relative; } }. Zero specificity + its own cascade layer: only a root that would otherwise bestaticchanges; unlayered app CSS, inline styles and later app layers still win. NogetComputedStyle, so it works when the root is attached before it is in the DOM or before its CSS loads.markGraphRoot/unmarkGraphRootinutils/graphInstance.ts): the class stays while another graph still uses the root, and is never removed if the application had set it itself.React
GraphCanvasis unchanged: its root.graph-canvasisposition: absolute, which beats the zero-specificity rule.The
position: relativeworkarounds are removed from the four package-contract apps.Tests
graph.test.ts): attach/detach,stop()vs full detach,unmount(), moving to another root, two graphs on one root, a class set by the application, inline position untouched.packages/graph/contract/app/graph.pw.tsandpackages/graph-playwright/contract/app/graph.pw.ts): the installed public styles make the canvas fill the root's padding box with padding and border, application positioning still applies in unlayered CSS and a later@layer app, and the existing connection-click scenario runs without a manual root-positioning workaround.node scripts/package-contract/run.mjs graph graph-playwrightpasses, including packed artifacts, public consumer type checks, imports, bundling, and Chromium scenarios. The changed test passes Prettier. Regression checks against a temporary browser bundle fail when the root rule is removed or moved outside its cascade layer, and pass after restoration. The full unit and E2E suites were not rerun for this test consolidation.Docs
The v1→v2 migration guide gets a checklist entry and a "Graph root positioning" section.
Known limitation: cascade layer order follows first declaration. If an app declares its layers (e.g. Tailwind v4
theme, base, components, utilities) before the graph styles load,gravity-graphcomes last and wins over them; the migration guide shows how to listgravity-graphfirst. A JS fallback (add the class only when the computed position isstatic) is possible if this turns out to matter.🤖 Generated with Claude Code
Summary by Sourcery
Make graph-attached roots containing blocks for their layers without overriding application positioning.
New Features:
graph-rootclass and public positioning styles.GRAPH_ROOT_CLASS_NAMEfor consumers that need to reference the graph root class.Bug Fixes:
Enhancements:
Documentation:
Tests: