Skip to content

Redraw the overlay once per expand or collapse, not up to five times - #357

Merged
IanMayo merged 1 commit into
mainfrom
claude/nifty-cannon-n3thwv
Nov 20, 2026
Merged

IanMayo merged 1 commit into
mainfrom
claude/nifty-cannon-n3thwv

Conversation

@IanMayo

@IanMayo IanMayo commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #355/#356, where the extra redraw after an expand was the source of the CI race.

What was happening

Measured by counting marker elements added to the overlay:

Expand Collapse
Before (1600×1000) 5 4
Before (smaller viewports) 3 2
After (every size, image and player) 1 1

Where the redraws came from:

  1. updateSVGLayout finishes in applyZoomTransform, which redraws the axes and every feature. The expand's measuring pass called it, and so did the settling pass.
  2. applyExpandLayout then redrew the axes and features again, explicitly.
  3. The expand grows the container that the ResizeObserver watches. handleResize then laid out and redrew twice more, even though nothing had changed size. The settling pass skipped corrections of 1 px or less (> 1), leaving a 1 px correction (CI's 526 → 527) for the observer to apply.

Changes

  • svgLayout.js: sizeSVG sizes the SVG, image and clip rects without drawing. updateSVGLayout is now sizeSVG plus the transform, so it is the one call that draws.
  • ExpandToggle.js:
    • The measuring pass only sizes.
    • Any settled difference is taken, 1 px included.
    • One updateSVGLayout draws, with no repeat redraw after it.
  • viewport.js: handleResize lays out again only when the gram's natural or render size moved, and doesn't repeat the redraw.
  • spectrogramImage.js: removed a renderAxes that updateSVGLayout had just done.

The final sizes are unchanged at every viewport tested: the same renderWidth and renderHeight as before.

Tests

  • New in player-expand.spec.js: expanding and collapsing each add exactly one marker element. It fails on the old code with 5 and passes on the new.
  • typecheck, lint, hygiene (the module line cap included) and the unit tests (371) pass.
  • Full Playwright suite: 541 of 542 pass. The one failure is marker-labels.spec.js:312, which also fails locally on main without this change, and passes on CI.

Review notes

  • handleResize now does nothing when the gram's size hasn't moved. That's right as long as only the natural and render dimensions decide the layout. If something else, such as the margins, ever comes to depend on the container's size, it needs to join that size check.
  • The new test covers the player. Image grams share the same functions, and the counts above were measured on both.

Generated by Claude Code

An expand redrew every persistent feature five times, a collapse four:

- updateSVGLayout ends in applyZoomTransform, which redraws the axes and
  features, and the expand's measuring pass called it as well as the
  settling one;
- applyExpandLayout then redrew both again explicitly;
- the expand grows the container the ResizeObserver watches, and
  handleResize relaid out and redrew twice more though nothing had
  changed size. A 1 px correction the settling pass skipped (`> 1`) was
  left for it to apply.

The measuring pass now only sizes (`sizeSVG`), takes any settled
difference, and the one updateSVGLayout draws. handleResize relays out
only when the gram's natural or render size moved, and no caller
repeats a redraw updateSVGLayout has already made. The final sizes are
unchanged.

A player-expand test counts the marker redraws: 5 before, 1 after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019erPajKv5JGH3Fj2Wt4i4x
@github-actions

Copy link
Copy Markdown
Contributor

PR Preview

Preview deployment is ready! View Preview

Last updated: 2026-11-20T12:08:28.480Z

@IanMayo
IanMayo merged commit d6fbc50 into main Nov 20, 2026
6 checks passed
@IanMayo
IanMayo deleted the claude/nifty-cannon-n3thwv branch November 20, 2026 12:29
github-actions Bot added a commit that referenced this pull request Nov 20, 2026
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