#23

Pause off-screen chart render loops via IntersectionObserver

OpenKyleKreuterwants to merge intofrom

What

Each chart's requestAnimationFrame paint loop now pauses while its canvas is outside the viewport and resumes — from preserved state, no re-reveal — when it scrolls back in. Pure performance; visually identical, no new prop.

Why

The reveal / star-wink loop runs forever: winkDue alone repaints ~10×/s per chart, indefinitely. On a dashboard with many charts (or a long page where most sit below the fold), every off-screen chart keeps doing full canvas repaints for nothing. Browsers throttle rAF for backgrounded tabs, but not for same-tab off-screen elements — that's the gap.

How

All four canvases share the same loop shape (let raf, a draw that self-schedules, a kickoff + cancelAnimationFrame cleanup). Each now:

  • keeps a visible flag; draw bails (and clears raf) while not visible,
  • starts/stops the loop from an IntersectionObserver on the canvas,
  • falls back to always-on when IntersectionObserver is undefined (SSR / tests).

Continue semantics: the loop's closure state (current, animStart, …) persists across a pause, so scrolling back in resumes without replaying the entrance. Below-the-fold charts simply animate in when first scrolled into view.

Touches cartesian-canvas.tsx, bar-canvas.tsx, pie-canvas.tsx, radar-canvas.tsx — no controller / context / API changes.

Tests

tests/offscreen.test.tsx (mocked IntersectionObserver + rAF spies) asserts the loop doesn't start until the canvas is visible, starts on intersect, and stops when it leaves the viewport. Full suite: 30 passing. Registry regenerated with npm run build:registry.

Summary by Comp AI

No blocking issues found.

Written for commit a2d06f3. New commits will trigger a re-review. Generated by Comp AI.

Activity

6
comp-ai-code-review[bot]4mo ago

✅ Comp AI code review complete — no issues found.

Reviewed commit a2d06f3.

Posted by Comp AI Code Reviews.

tripwire-sh[bot]4mo ago

passed — nothing tripped. good to merge.

tripwire-dev[bot]4mo ago

passed — nothing tripped. good to merge.

comp-ai-code-review[bot]reviewed4mo ago
comp-ai-code-review[bot]4mo ago

No blocking issues found across the changed files.

Posted by Comp AI Code Reviews.