Skip to content
Source
Sign inSign up
TanStack/charts

[Bug] Printed charts keep their screen width: resize redraw waits for an animation frame #228

Send to my agent
Openpiecyk opened this issue 0 comments
piecykcommented

Version: @tanstack/charts 1.1.0, Chromium. Also seen with Playwright page.pdf().

A responsive chart (no width) is drawn at its screen width. When the page is printed or exported with page.pdf(), the print layout narrows the container but the chart is not redrawn. The browser scales the screen drawing down, so text and strokes shrink, and a fixed-height chart is letterboxed with empty space above and below.

Why

  • The root SVG uses width="100%" height="100%" with viewBox="0 0 <screenWidth> <height>", so a width change scales the existing drawing.
  • ResizeObserver sees the new size, but the redraw goes through scheduleRender(), which waits for requestAnimationFrame (renderer.ts).
  • Print and page.pdf() lay out and paint without running an animation frame, so the redraw never happens before the page is printed.

Repro

  1. Render <Chart definition={…} height={320} ariaLabel="…" /> in a container with a percentage width.
  2. Open print preview in a viewport wider than the page, or call page.pdf({ format: 'A4' }) on a 1200px-wide page.
  3. The chart is a scaled-down screen drawing, not a chart laid out for the page width.

Expected

The chart redraws at the print container width before printing.

Workaround

On the print media change, measure the container and pass it as a fixed width inside flushSync, then remove width when print ends. It works, but every app that prints has to know about it.

  1. piecyk linked this to #229

Sign in to join this conversation.