Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(insights): keep hog-charts tooltip on screen via autoUpdate (#60871)

Sam Pennington01dd93c21376
diff --git a/frontend/src/lib/hog-charts/overlays/Tooltip.tsx b/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
index 594bc5bfd9d8..478b0e39c8e0 100644
--- a/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
+++ b/frontend/src/lib/hog-charts/overlays/Tooltip.tsx
@@ -1,4 +1,4 @@
-import { flip, FloatingPortal, offset, shift, useFloating, type VirtualElement } from '@floating-ui/react'
+import { autoUpdate, flip, FloatingPortal, offset, shift, useFloating, type VirtualElement } from '@floating-ui/react'
import React, { useLayoutEffect, useMemo } from 'react'
import { useChartLayout } from '../core/chart-context'
@@ -67,6 +67,11 @@ export function Tooltip<Meta = unknown>({
placement: placement === 'follow-data' ? 'right' : 'right-start',
strategy: 'fixed',
middleware: TOOLTIP_MIDDLEWARE,
+ // Re-run the middleware (notably `flip`/`shift`) once the portaled tooltip reaches its
+ // real `max-content` size and whenever the page scrolls/resizes — without this the first
+ // position is computed against a still-zero-width element, so `flip` never kicks in and
+ // the tooltip can stay clipped off the right edge (e.g. on the last bar of a chart).
+ whileElementsMounted: autoUpdate,
})
useLayoutEffect(() => {