Renderer treats a sub-pixel width difference as a resize, which cancels the `motion()` entrance #182
Version: @tanstack/charts 1.0.0 (unchanged on main).
The first render sizes the scene from getComputedStyle(container).width (contentBoxDimension → cssPixelValue). Chromium serializes that rounded, e.g. 569.594px. The ResizeObserver then reports the exact contentRect.width, 569.59375, and responsiveSizeChanged compares the two with !==:
next.width !== scene.width
So on any container with a fractional width (a 32% grid column, minmax(…)), the observer's first callback schedules a "resize" render. With motion()'s default resize: false, that render paints the final frame without animation, and the entrance is cancelled one frame after it starts. Containers that happen to be a whole number of pixels wide animate fine, so it looks random from the app side.
Repro: mount a Chart with renderer={motion()} inside <div style="width: 569.59375px">. data-ts-motion-state goes running, and the SVG is replaced on the first observer callback without ever reaching finished.
Suggested fix: treat a difference under half a pixel as no change (Math.abs(next.width - scene.width) >= 0.5, same for height), or take the first measurement from a source with the same precision as the observer. We're running the first as a pnpm patch, and it restores the entrance.
Thanks @luciensolteo for the original report and @toomingos for separating out the real-resize follow-up. The fractional first-observation fix shipped in 1.1.0. PR #218 now documents the remaining policy explicitly: with resize: false, a real resize cancels an entrance and paints the resized final scene; resize: true animates from the currently painted geometry. The default is unchanged.
The merged motion reference covers this behavior, and two regression cases verify both settings: https://github.com/TanStack/charts/blob/main/docs/reference/motion.md. Full validation passed before merge, including 2,220 main-suite tests. This addresses the documentation option in the follow-up, so I am closing this issue. The separate tooltip patch in #218 is still moving through the 1.1.1 release workflow.
tannerlinsley closed this
Sign in to join this conversation.
Follow-up on 1.1.0 (
57774e14a1a86081eddb3a23523724a40da05640): the fractional first-observation case from the report is fixed, but a real size change while the entrance is still running still cancels it."resize"render wheneverresponsiveSizeChanged()is true (renderer.ts:349-402, the observer at renderer.ts:371-402; the 1.1.0 precision adoption only applies to the first callback).motion({ resize: false }),resolveAnimationreturnsundefinedfor a resize render (renderer.ts:1470-1486), and inmotion().renderthe scene is marked as resized andanimateis false (motion.ts:961-981). It then callscancelAnimation()unconditionally (motion.ts:985), which tears down the entrance that is still running, and paints the final frame.Repro: mount a
Chartwithrenderer={motion()}in a container whose width changes 100 ms after mount (a sidebar that opens, a scrollbar appearing, a font swap shifting layout).data-ts-motion-stategoesrunningand is replaced without reachingfinished.This is the usual case on a page where layout settles after first paint, and the entrance looks cut short.
Read from source, not run in jsdom (no layout).
Proposal, either:
resize: false.