Skip to content

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

fix(dashboards): Avoid nested scrollbars for scores widget (#17713)

Ben Bachem2ca0e1b0237d
diff --git a/web/src/features/widgets/components/DashboardGrid.tsx b/web/src/features/widgets/components/DashboardGrid.tsx
index 9c47215447..c4567b1e95 100644
--- a/web/src/features/widgets/components/DashboardGrid.tsx
+++ b/web/src/features/widgets/components/DashboardGrid.tsx
@@ -10,7 +10,7 @@ import {
import { DashboardWidget } from "@/src/features/widgets";
import type { ResolvedReadPath } from "@/src/features/events";
import { type FilterState } from "@langfuse/shared";
-import { useState, useEffect, useRef } from "react";
+import { useState, useEffect, useRef, useCallback } from "react";
export type DashboardPlacement = WidgetPlacement | PresetPlacement;
@@ -113,6 +113,18 @@ export function DashboardGrid({
onDuplicatePreset?: (anchor: PresetPlacement) => void;
}) {
const { containerRef, width } = useDebouncedContainerWidth(200);
+ const [contentHeights, setContentHeights] = useState<Record<string, number>>(
+ {},
+ );
+ const handleContentHeightChange = useCallback(
+ (placementId: string, height: number) => {
+ setContentHeights((current) => {
+ if (current[placementId] === height) return current;
+ return { ...current, [placementId]: height };
+ });
+ },
+ [],
+ );
// Rows stay 16:9-proportional to column width, with a floor so tiles keep a
// usable height on narrow screens — below the floor, widget content (chart
// floors, table rows) no longer fits and tiles scroll internally; the grid
@@ -128,16 +140,26 @@ export function DashboardGrid({
const isSmallScreen = useMediaQuery("(max-width: 1023.98px)");
// Convert WidgetPlacement to react-grid-layout format
- const layout = widgets.map((w) => ({
- i: w.id,
- x: w.x,
- y: w.y,
- w: w.x_size,
- h: w.y_size,
- isDraggable: canEdit && !isSmallScreen, // Disable dragging on small screens
- minW: 2,
- minH: 2,
- }));
+ const layout = widgets.map((w) => {
+ const contentHeight = contentHeights[w.id];
+ const contentRows = contentHeight
+ ? Math.ceil((contentHeight + 16) / (rowHeight + 16))
+ : 0;
+
+ return {
+ i: w.id,
+ x: w.x,
+ y: w.y,
+ w: w.x_size,
+ h:
+ w.type === "preset" && w.presetId === "home-score-analytics"
+ ? Math.max(w.y_size, contentRows)
+ : w.y_size,
+ isDraggable: canEdit && !isSmallScreen, // Disable dragging on small screens
+ minW: 2,
+ minH: 2,
+ };
+ });
const handleLayoutChange = (newLayout: any[]) => {
// Safety checks: prevent layout changes on small screens and when editing is disabled
@@ -182,6 +204,14 @@ export function DashboardGrid({
onLockedEditAttempt={onLockedEditAttempt}
readOnly={readOnly}
onDuplicatePreset={onDuplicatePreset}
+ heightBehavior={
+ widget.presetId === "home-score-analytics"
+ ? {
+ mode: "content",
+ onHeightChange: handleContentHeightChange,
+ }
+ : { mode: "fixed" }
+ }
/>
) : (
<DashboardWidget
diff --git a/web/src/features/widgets/components/PresetDashboardWidget.tsx b/web/src/features/widgets/components/PresetDashboardWidget.tsx
index 1b29d3e574..9e47c61624 100644
--- a/web/src/features/widgets/components/PresetDashboardWidget.tsx
+++ b/web/src/features/widgets/components/PresetDashboardWidget.tsx
@@ -1,6 +1,6 @@
import { showErrorToast, showSuccessToast } from "@/src/features/notifications";
import { useHasProjectAccess } from "@/src/features/rbac";
-import { useMemo } from "react";
+import { useEffect, useMemo, useRef } from "react";
import {
CopyIcon,
CopyPlusIcon,
@@ -55,6 +55,7 @@ export function PresetDashboardWidget({
onLockedEditAttempt,
readOnly,
onDuplicatePreset,
+ heightBehavior,
}: {
projectId: string;
dashboardId: string;
@@ -79,6 +80,12 @@ export function PresetDashboardWidget({
* Passed only on editable (non-locked) dashboards.
*/
onDuplicatePreset?: (anchor: PresetPlacement) => void;
+ heightBehavior:
+ | { mode: "fixed" }
+ | {
+ mode: "content";
+ onHeightChange: (placementId: string, height: number) => void;
+ };
}) {
const metricsVersion: ViewVersion = readPath === "v4" ? "v2" : "v1";
@@ -97,6 +104,35 @@ export function PresetDashboardWidget({
Boolean(onLockedEditAttempt);
const renderPreset = getHomePreset(placement.presetId);
+ const contentRef = useRef<HTMLDivElement>(null);
+ const onHeightChange =
+ heightBehavior.mode === "content"
+ ? heightBehavior.onHeightChange
+ : undefined;
+
+ useEffect(() => {
+ if (!onHeightChange) return;
+
+ const element = contentRef.current;
+ if (!element) return;
+
+ const reportHeight = () => {
+ onHeightChange(
+ placement.id,
+ Math.max(element.getBoundingClientRect().height, element.scrollHeight),
+ );
+ };
+ const resizeObserver = new ResizeObserver(reportHeight);
+ const mutationObserver = new MutationObserver(reportHeight);
+ resizeObserver.observe(element);
+ mutationObserver.observe(element, { childList: true, subtree: true });
+ reportHeight();
+
+ return () => {
+ resizeObserver.disconnect();
+ mutationObserver.disconnect();
+ };
+ }, [onHeightChange, placement.id]);
const ctx: PresetWidgetContext = useMemo(() => {
const fromTimestamp = dateRange
@@ -133,9 +169,8 @@ export function PresetDashboardWidget({
metricsVersion,
schedulerId,
syncId: dashboardId,
- // Stretch to the tile; when the card's intrinsic content is taller
- // (fixed chart min-heights, expanded tables) the wrapper scrolls
- // instead of clipping.
+ // Most presets stretch to their fixed tile. Score Analytics is measured
+ // by the grid because each selected score adds another chart row.
className: "min-h-full",
};
}, [
@@ -190,8 +225,19 @@ export function PresetDashboardWidget({
}
return (
- <div className="group relative h-full w-full">
- <div className="h-full w-full overflow-y-auto">{renderPreset(ctx)}</div>
+ <div
+ className={`group relative w-full ${heightBehavior.mode === "content" ? "" : "h-full"}`}
+ >
+ <div
+ ref={contentRef}
+ className={
+ heightBehavior.mode === "content"
+ ? "w-full"
+ : "h-full w-full overflow-y-auto"
+ }
+ >
+ {renderPreset(ctx)}
+ </div>
{/* The menu (copy) stays available on read-only surfaces like Home —
only the edit affordances (drag, delete) are gated. */}
<div className="bg-background/95 absolute top-2 right-2 z-10 hidden items-center gap-2 rounded-md border px-1.5 py-1 shadow-sm group-hover:flex has-data-[state=open]:flex">