Skip to content

Keep a graph's opening view while a new scope is laid out - #131

Open
agorischek wants to merge 3 commits into
mainfrom
agorischek/focus-opening-stale-layout
Open

agorischek wants to merge 3 commits into
mainfrom
agorischek/focus-opening-stale-layout

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

A graph zoomed past its stage for a moment as it opened in a host that applies the Changes scope, and a check that measured in that moment saw it scroll sideways. The hosted gallery's WebKit test caught it: div.graph-scroll 975>748 (scale 0.923, zoom 1.317655, width 1022).

Why it happened

  1. A host's frame opens provisionally, drawing every item, then the host sends its filter with the Changes scope. That brings a focus request on the changes ({on: 'changes'}).
  2. GraphCanvas lays the new scope out in the background, and meanwhile draws the old layout with the new props.
  3. LaidOutGraph therefore computed focusArea for the new scope's changes inside the old drawing. focusOpening then framed them at full size: zoom = 0.923 / 0.700, and a 1022-unit drawing in a 748px stage.
  4. The view stayed like that until the new layout arrived, about 30ms later. It reproduced on every load in Chromium and WebKit.

Fix

  • GraphCanvas passes stale while it draws a layout made for earlier props.
  • LaidOutGraph takes no focus area while the layout is stale, so the old layout keeps its fitted opening. The focus applies once the scope's own layout is drawn.
  • Views the person has zoomed or panned are unaffected, since the opening doesn't apply to them.

Test

  • The stage gains filter(payload), which sends the host's filter message (StageApi, StageHandle, the Inspector's stage).
  • harness/browser/scope-opening.spec.ts opens graph/platform-worker in diff mode at 520px, where everything fits below full size. It records every view the frame commits, through a MutationObserver inside it, then sends the Changes scope.
  • It asserts that the old layout keeps its opening zoom and that nothing is drawn wider than its stage.
  • Without the fix, the spec fails: the old layout re-zooms to 1.213.

Verified locally

  • tools check --fast (typecheck included) and tools test packages/renderers/kit pass.
  • The new spec passes in chromium-desktop with the fix and fails without it.
  • In the hosted gallery, rebuilt on this branch, codebase architecture now goes straight from the provisional fit (0.700) to the Changes layout (1.000) in both engines.

A host draws every item, then sends its Changes scope with a focus on the
changes. The graph lays the scope out in the background and meanwhile
draws the old layout with the new props, so it framed the new scope's
changes within the old drawing and zoomed it past its stage until the new
layout arrived. GraphCanvas now marks that layout stale, and LaidOutGraph
opens it on no focus: it stays fitted.

The stage gains filter(), sending the host's filter message, so a harness
spec can apply the Changes scope after the first paint.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Clearing area during relayout drops an already-applied focus and causes a visible zoom jump; the committed focus should be retained while stale and covered by a regression test.

1 open issue
What changed in this PR

This PR addresses transient graph overflow when a host applies the Changes scope while its new layout is still pending.

Changes:

  • Marks retained layouts as stale and defers focus-area calculation until the replacement layout arrives.
  • Exposes host filter messages through the Inspector stage and testing APIs.
  • Adds a browser regression test that records intermediate graph widths and zoom levels.
File Description
packages/​renderers/​testing/​src/​types.ts Adds filter to StageApi.
packages/​renderers/​testing/​playwright/​index.ts Exposes filter through the Playwright stage handle.
packages/​renderers/​kit/​src/​react/​graph-canvas/​laid-out-graph.tsx Suppresses focus-area calculation for stale layouts.
packages/​renderers/​kit/​src/​react/​graph-canvas/​drawing.ts Defines the optional stale-layout prop.
packages/​renderers/​kit/​src/​react/​graph-canvas/​canvas.tsx Tracks and forwards layout staleness.
packages/​renderers/​harness/​browser/​scope-opening.spec.ts Tests opening zoom and width during scope changes.
packages/​host/​inspector/​src/​fixtures/​stage.ts Forwards filter payloads to the renderer frame.
packages/​host/​inspector/​src/​fixtures/​session.ts Connects the stage API’s filter method.

Review effort: Balanced

Comment on lines 72 to 80
// A layout drawn while the current props are laid out may hold items the focus no longer names, or more: framing the
// focus within it would zoom the old drawing past its fit. It stays fitted until its own layout arrives.
const stale = props.stale === true
const area = useMemo(
() => (stale ? undefined : focusArea(transition, diff, props.model, request, shown)),
[stale, transition, diff, props.model, request, shown],
)
const drawn = nodes.map(node => ({x: node.x - node.width / 2, y: node.y - node.height / 2, width: node.width, height: node.height}))
const {zoom, scale, borders, keep} = useGraphZoom(scroller, framing, bounds, props.onAction, {area, request}, orientation, drawn, hold)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants