[Bug] Printed charts keep their screen width: resize redraw waits for an animation frame #228
Send to my agentOpen
piecyk opened this issue ·0 comments
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%"withviewBox="0 0 <screenWidth> <height>", so a width change scales the existing drawing. ResizeObserversees the new size, but the redraw goes throughscheduleRender(), which waits forrequestAnimationFrame(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#
- Render
<Chart definition={…} height={320} ariaLabel="…" />in a container with a percentage width. - Open print preview in a viewport wider than the page, or call
page.pdf({ format: 'A4' })on a 1200px-wide page. - 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.
piecyk linked this to #229
Sign in to join this conversation.