Tooltip reappears and sticks after mouseleave: pending rAF-throttled mousemove is not cancelled (3.8.0 – 3.11.0-canary.4)
What is the current behavior?
With the default throttleDelay: 'raf', mouseMoveMiddleware handles mousemove inside a requestAnimationFrame callback. RechartsWrapper's onMouseLeave dispatches mouseLeaveChart() immediately but does not cancel that pending frame. When a mouseleave arrives in the same frame as the last mousemove, the leave clears the tooltip, then the pending frame fires setMouseOverAxisIndex and the tooltip comes back. It stays visible at the old position until the next hover.
A real-world trigger: a click that re-renders the page so the chart moves out from under a pointer that did not move (the chart gets mousemove, click, then mouseout in one frame).
Also, rafId, timeoutId and latestChartPointer are module-level, so every chart on the page shares one pending frame, although the source comment assumes one per store.
What is the expected behavior?
After mouseleave, the tooltip stays hidden.
Please provide a demo of the problem in a sandbox
Any <LineChart> with <XAxis /> <YAxis /> <Tooltip isAnimationActive={false} /> <Line />. Hover it once, then run in the console:
const el = document.querySelector('.recharts-wrapper'), r = el.getBoundingClientRect();
el.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX: r.left + r.width * 0.4, clientY: r.top + r.height / 2 }));
el.dispatchEvent(new MouseEvent('mouseout', { bubbles: true, clientX: r.right + 100, clientY: r.top }));
el.dispatchEvent(new MouseEvent('mouseleave', { clientX: r.right + 100, clientY: r.top }));The tooltip is visible on the next frame and stays visible: 20/20 trials on 3.8.0, 3.10.1 and 3.11.0-canary.4, and 0/20 with throttledEvents={[]} (which confirms the rAF throttle is the cause). Real input shows the same thing when two CDP Input.dispatchMouseEvent mouseMoved events (inside, then outside the chart) land in one frame: 7–14 of 20 trials.
Suggested fix: in mouseEventsMiddleware, on mouseLeaveChart, cancelAnimationFrame(rafId), clearTimeout(timeoutId) and null latestChartPointer; and keep that state per store rather than per module.
Which versions of Recharts, and which browser / OS are affected by this issue? Did this work in previous versions of Recharts?
- recharts 3.8.0, 3.10.1 and 3.11.0-canary.4 (the middleware is unchanged on
main). - Chromium (Playwright), React 19, macOS and Linux.
- Not tested on 2.x; the rAF-throttled middleware is a 3.x design.
Source: recharts/recharts