Skip to content
Source
Sign inSign up
TanStack/charts

React custom tooltip body shows the previous point for a frame after a pointer move #239

Openpiotrkulpinski(GitHub profile, opens in a new tab) opened this issue 0 comments

What happens

With a custom React tooltip body (renderTooltipBody from @tanstack/react-charts/tooltip), moving the pointer to another point shows the previous point's body at the new point's position for one frame. The tooltip then updates. It reads as a flicker on every hover move.

Why

paint() in charts-core/src/tooltip.ts positions the tooltip element and calls bodyChange in the same task. The React adapter's TooltipBody answers with a plain setTarget(). React schedules a state update from a native pointermove listener at continuous priority, which renders in a later task. The browser paints in between, so the frame shows the moved element with the old body.

A keyboard move doesn't show it: React flushes a discrete-event update in a microtask, before the paint.

Reproduce

Any RendererChart with focus: "group-x" and a renderTooltipBody. Move the pointer slowly across the points, or record the screen and step through the frames.

Seen on @tanstack/charts 1.0.0 (/react/tooltip) and still present on main (a2e82ab).

Possible fix

Flush the body update with flushSync when the call comes from an interaction. Keep the plain setState when the adapter repaints inside React's layout effect (adapter.update/destroy), where flushSync warns ("flushSync was called from inside a lifecycle method"). I'll open a PR with that.

Sign in to join this conversation.