Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(events): keep Pulse touch tooltip on-screen at viewport edges (LFE-14451) (#15524)

Nikita Kabardin84648830c1d4
diff --git a/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx b/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx
index f434b9aecb..404edd693a 100644
--- a/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx
+++ b/web/src/features/events/components/outlier-strip/OutlierBarStrip.tsx
@@ -1,4 +1,4 @@
-import { useMemo, useRef, useState } from "react";
+import { useCallback, useMemo, useRef, useState } from "react";
import { cn } from "@/src/utils/tailwind";
import { X } from "lucide-react";
import { Button } from "@/src/components/ui/button";
@@ -99,6 +99,38 @@ export function OutlierBarStrip({
// Drag gesture bookkeeping lives in a ref: pointermove during a drag only
// updates the SHARED selection via onSelectionChange, never local state.
const dragRef = useRef<{ startX: number; dragging: boolean } | null>(null);
+ // The pinned preview centers on its anchor, so keeping it on-screen needs
+ // the rendered size. A callback ref measures in the commit phase (before
+ // paint — no mispositioned flash) and attaches a ResizeObserver so content
+ // changes while pinned (a live refetch growing the count, the Explore
+ // button toggling) re-clamp instead of drifting on a stale size.
+ const [previewSize, setPreviewSize] = useState<{
+ width: number;
+ height: number;
+ } | null>(null);
+ const previewResizeObserverRef = useRef<ResizeObserver | null>(null);
+ const measurePreview = useCallback((el: HTMLDivElement | null) => {
+ previewResizeObserverRef.current?.disconnect();
+ previewResizeObserverRef.current = null;
+ if (!el) {
+ setPreviewSize(null);
+ return;
+ }
+ const measure = () =>
+ setPreviewSize((prev) => {
+ const width = el.offsetWidth;
+ const height = el.offsetHeight;
+ return prev && prev.width === width && prev.height === height
+ ? prev
+ : { width, height };
+ });
+ measure();
+ if (typeof ResizeObserver !== "undefined") {
+ const observer = new ResizeObserver(measure);
+ observer.observe(el);
+ previewResizeObserverRef.current = observer;
+ }
+ }, []);
const metricSpec = OUTLIER_STRIP_METRICS[metric];
const color = METRIC_COLOR[metric];
@@ -259,6 +291,11 @@ export function OutlierBarStrip({
const previewHasData =
previewStats !== null &&
(previewStats.count > 0 || previewStats.value !== null);
+ // First render (pre-measure) treats the box as zero-width; the commit-phase
+ // measurement re-renders with the real clamp before the browser paints.
+ const previewHalfWidth = (previewSize?.width ?? 0) / 2;
+ const viewportWidth =
+ typeof window !== "undefined" ? window.innerWidth : Number.MAX_SAFE_INTEGER;
return (
<div className={cn("relative", className)} style={{ width: widthPx }}>
@@ -461,15 +498,23 @@ export function OutlierBarStrip({
{activePreview && previewStats && (
<Layer name="tooltip">
<div
- className="bg-popover text-popover-foreground fixed rounded border px-2 py-1.5 font-mono text-[11px] leading-tight whitespace-nowrap shadow-md"
+ key={`${activePreview.fromMs}:${activePreview.toMs}`}
+ ref={measurePreview}
+ className="bg-popover text-popover-foreground fixed max-w-[calc(100vw-16px)] rounded border px-2 py-1.5 font-mono text-[11px] leading-tight whitespace-nowrap shadow-md"
style={{
+ // Clamp the center so the measured box stays fully on-screen —
+ // edge-of-viewport taps would otherwise clip half the tooltip.
left: Math.min(
- Math.max(activePreview.anchorX, 90),
- typeof window !== "undefined"
- ? window.innerWidth - 90
- : activePreview.anchorX,
+ Math.max(activePreview.anchorX, 8 + previewHalfWidth),
+ Math.max(
+ viewportWidth - 8 - previewHalfWidth,
+ 8 + previewHalfWidth,
+ ),
+ ),
+ top: Math.max(
+ activePreview.anchorY - 6,
+ (previewSize?.height ?? 0) + 8,
),
- top: activePreview.anchorY - 6,
transform: "translate(-50%, -100%)",
}}
>