Skip to content

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

fix(dashboards): one-way sizing for home bar widgets to stop chart wobble (#15220)

Nikita Kabardin887fe70d9e2f
diff --git a/web/src/features/dashboard/components/TracesBarListChart.tsx b/web/src/features/dashboard/components/TracesBarListChart.tsx
index 973eded76c..f31959862e 100644
--- a/web/src/features/dashboard/components/TracesBarListChart.tsx
+++ b/web/src/features/dashboard/components/TracesBarListChart.tsx
@@ -6,9 +6,8 @@ import { TotalMetric } from "@/src/features/dashboard/components/TotalMetric";
import { compactNumberFormatter } from "@/src/utils/numbers";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
-import { Chart } from "@/src/features/widgets/chart-library/Chart";
import { formatMetric } from "@/src/features/widgets/chart-library/utils";
-import { barListToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
+import { BarListChartArea } from "@/src/features/dashboard/components/cards/BarListChartArea";
import { traceViewQuery } from "@/src/features/dashboard/lib/dashboard-utils";
import { useScheduledDashboardExecuteQuery } from "@/src/hooks/useDashboardQueryScheduler";
import { useFitRowCount } from "@/src/features/dashboard/hooks/useFitRowCount";
@@ -118,7 +117,9 @@ export const TracesBarListChart = ({
// Fit the number of bars to the tile height instead of a fixed count: the
// collapsed view renders exactly as many bars as fill the measured chart area
- // (no scrollbar, no dead gap), and "Show all" reveals the rest. (LFE-11035)
+ // (no scrollbar, no dead gap), and "Show all" reveals the rest. The hook
+ // measures a layout-guaranteed box and hands `height` down to a pure chart
+ // (BarListChartArea) — one-way, no measure/resize feedback. (LFE-11035, LFE-11060)
const { containerRef, rowCount, height } = useFitRowCount({
rowHeightPx: BAR_ROW_HEIGHT,
reservedPx: CHART_AXIS_PADDING,
@@ -155,50 +156,18 @@ export const TracesBarListChart = ({
description="Total traces tracked"
/>
{transformedTraces.length > 0 ? (
- // The chart fills the leftover tile height (flex-1) and never forces
- // the card past its tile. Collapsed, it renders only the bars that fit
- // the measured area and sizes the chart to that same measured height,
- // so the bars spread to use it: a sparse list has no dead gap and a
- // full one has no scrollbar. Expanded, it grows to the bars' natural
- // height and this viewport scrolls within the tile. (LFE-11035,
- // revises LFE-10813)
- <div
- ref={containerRef}
- className="mt-4 min-h-0 w-full flex-1 overflow-y-auto"
- >
- <div
- className="w-full"
- style={{
- // Collapsed: fill the measured area exactly (definite px so
- // recharts renders and the bars spread to use the height).
- // Expanded: grow to the bars' natural height so the viewport
- // above scrolls.
- height: isExpanded
- ? adjustedData.length * BAR_ROW_HEIGHT + CHART_AXIS_PADDING
- : (height ?? 200),
- }}
- >
- <Chart
- chartType="HORIZONTAL_BAR"
- data={barListToDataPoints(adjustedData)}
- metricFormatter={(value) =>
- formatMetric(value, { style: "full" })
- }
- config={{
- metric: {
- label: "Traces",
- },
- }}
- rowLimit={MAX_EXPANDED_BARS}
- chartConfig={{
- type: "HORIZONTAL_BAR",
- row_limit: MAX_EXPANDED_BARS,
- unit: "traces",
- show_value_labels: true,
- }}
- />
- </div>
- </div>
+ <BarListChartArea
+ containerRef={containerRef}
+ measuredHeightPx={height}
+ isExpanded={isExpanded}
+ data={adjustedData}
+ barRowHeightPx={BAR_ROW_HEIGHT}
+ axisPaddingPx={CHART_AXIS_PADDING}
+ maxExpandedBars={MAX_EXPANDED_BARS}
+ metricLabel="Traces"
+ unit="traces"
+ metricFormatter={(value) => formatMetric(value, { style: "full" })}
+ />
) : (
<NoDataOrLoading
isLoading={isLoading || traces.isPending || totalTraces.isPending}
diff --git a/web/src/features/dashboard/components/UserChart.tsx b/web/src/features/dashboard/components/UserChart.tsx
index f0771fca2d..d35ab3736c 100644
--- a/web/src/features/dashboard/components/UserChart.tsx
+++ b/web/src/features/dashboard/components/UserChart.tsx
@@ -9,8 +9,7 @@ import { costFormatter } from "@/src/utils/numbers";
import { NoDataOrLoading } from "@/src/components/NoDataOrLoading";
import { type QueryType, type ViewVersion } from "@langfuse/shared/query";
import { mapLegacyUiTableFilterToView } from "@/src/features/dashboard/lib/dashboardUiTableToViewMapping";
-import { Chart } from "@/src/features/widgets/chart-library/Chart";
-import { barListToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
+import { BarListChartArea } from "@/src/features/dashboard/components/cards/BarListChartArea";
import { traceViewQuery } from "@/src/features/dashboard/lib/dashboard-utils";
import { useScheduledDashboardExecuteQuery } from "@/src/hooks/useDashboardQueryScheduler";
import { useFitRowCount } from "@/src/features/dashboard/hooks/useFitRowCount";
@@ -168,7 +167,8 @@ export const UserChart = ({
// Fit the number of bars to the tile height (see TracesBarListChart): render
// exactly the bars that fill the measured chart area, no scrollbar, and defer
- // the rest to "Show all". (LFE-11035)
+ // the rest to "Show all". The measured `height` flows one-way into the pure
+ // BarListChartArea chart. (LFE-11035, LFE-11060)
const { containerRef, rowCount, height } = useFitRowCount({
rowHeightPx: BAR_ROW_HEIGHT,
reservedPx: CHART_AXIS_PADDING,
@@ -225,46 +225,17 @@ export const UserChart = ({
metric={item.totalMetric}
description={item.metricDescription}
/>
- {/* The chart fills the leftover tile height. Collapsed it
- renders only the bars that fit the measured area and
- sizes the chart to that same height, so they spread to
- use it: no dead gap for a sparse list, no scrollbar for a
- full one. Expanded it grows to the bars' natural height
- and this viewport scrolls within the tile. Mirrors
- TracesBarListChart. (LFE-11035, revises LFE-10813) */}
- <div
- ref={containerRef}
- className="mt-4 min-h-0 w-full flex-1 overflow-y-auto"
- >
- <div
- className="w-full"
- style={{
- // Collapsed: fill the measured area (definite px).
- // Expanded: grow to the bars' natural height so the
- // viewport scrolls.
- height: isExpanded
- ? shown.length * BAR_ROW_HEIGHT + CHART_AXIS_PADDING
- : (height ?? 200),
- }}
- >
- <Chart
- chartType="HORIZONTAL_BAR"
- data={barListToDataPoints(shown)}
- config={{
- metric: {
- label: item.chartMetricLabel,
- },
- }}
- rowLimit={maxNumberOfEntries.expanded}
- chartConfig={{
- type: "HORIZONTAL_BAR",
- row_limit: maxNumberOfEntries.expanded,
- unit: item.chartUnit,
- show_value_labels: true,
- }}
- />
- </div>
- </div>
+ <BarListChartArea
+ containerRef={containerRef}
+ measuredHeightPx={height}
+ isExpanded={isExpanded}
+ data={shown}
+ barRowHeightPx={BAR_ROW_HEIGHT}
+ axisPaddingPx={CHART_AXIS_PADDING}
+ maxExpandedBars={maxNumberOfEntries.expanded}
+ metricLabel={item.chartMetricLabel}
+ unit={item.chartUnit}
+ />
</div>
) : (
<NoDataOrLoading
diff --git a/web/src/features/dashboard/components/cards/BarListChartArea.tsx b/web/src/features/dashboard/components/cards/BarListChartArea.tsx
new file mode 100644
index 0000000000..94e01c798b
--- /dev/null
+++ b/web/src/features/dashboard/components/cards/BarListChartArea.tsx
@@ -0,0 +1,98 @@
+import { Chart } from "@/src/features/widgets/chart-library/Chart";
+import { type MetricFormatterFunction } from "@/src/features/widgets/chart-library/chart-props";
+import { barListToDataPoints } from "@/src/features/dashboard/lib/chart-data-adapters";
+
+export type BarListDataPoint = {
+ name: string;
+ value: number;
+};
+
+/**
+ * Presentational, one-way chart area for the fit-to-tile horizontal bar cards
+ * (Traces, User consumption). It renders the leftover-height region a
+ * {@link useFitRowCount} hook observes plus a definite-height inner box that
+ * hosts a pure {@link Chart}. Data flows one way: the hook measures the
+ * layout-guaranteed `flex-1` box (which this component never resizes) and hands
+ * a concrete pixel `measuredHeightPx` down here; the chart is then a pure
+ * function of that number and the already-sliced `data`. It never measures
+ * itself, so there is no measure -> setState -> resize -> remeasure feedback.
+ * Mirrors how DashboardGrid's `useDebouncedContainerWidth` measures once and
+ * passes `width` down. (LFE-11060)
+ */
+export function BarListChartArea({
+ containerRef,
+ measuredHeightPx,
+ isExpanded,
+ data,
+ barRowHeightPx,
+ axisPaddingPx,
+ maxExpandedBars,
+ metricLabel,
+ unit,
+ metricFormatter,
+}: {
+ /** Callback ref from `useFitRowCount`; attaches the ResizeObserver here. */
+ containerRef: (node: HTMLElement | null) => void;
+ /**
+ * Measured height of the observed box in px, or `null` before the first
+ * measurement (SSR / initial paint). Recharts needs a definite height, so we
+ * fall back until then.
+ */
+ measuredHeightPx: number | null;
+ isExpanded: boolean;
+ /** Bars to show, already sliced to the fitted/expanded count by the caller. */
+ data: BarListDataPoint[];
+ barRowHeightPx: number;
+ axisPaddingPx: number;
+ maxExpandedBars: number;
+ metricLabel: string;
+ unit: string;
+ metricFormatter?: MetricFormatterFunction;
+}) {
+ return (
+ // Two boxes, deliberately split:
+ //
+ // - the OUTER box carries the ResizeObserver ref and does NOT scroll. Its
+ // height is pure flex layout (flex-1 of the card), so it can never be
+ // reduced by a scrollbar appearing on a descendant. useFitRowCount
+ // therefore measures a stable value and cannot enter a
+ // measure -> shrink -> remeasure loop — even in browsers/OSes whose
+ // scrollbars consume layout space (classic, non-overlay).
+ // - the INNER box scrolls: `overflow-y-auto` lets the expanded list scroll
+ // within the tile, while `overflow-x-hidden` stops a horizontal scrollbar
+ // from ever appearing (the chart is width-fitted, so nothing is clipped).
+ // A horizontal scrollbar is what would otherwise consume vertical space
+ // and flicker on wide content (e.g. many long trace names).
+ //
+ // The chart is a pure function of the passed dimensions and never measures
+ // itself. Collapsed, the sized box takes the measured height so the bars
+ // spread to fill it (no dead gap, no scrollbar); expanded, it grows to the
+ // bars' natural height and the inner box scrolls. (LFE-11060, revises LFE-11035)
+ <div ref={containerRef} data-fit-box className="mt-4 min-h-0 w-full flex-1">
+ <div className="h-full min-h-0 w-full overflow-x-hidden overflow-y-auto">
+ <div
+ className="w-full"
+ style={{
+ height: isExpanded
+ ? data.length * barRowHeightPx + axisPaddingPx
+ : (measuredHeightPx ?? 200),
+ }}
+ >
+ <Chart
+ chartType="HORIZONTAL_BAR"
+ data={barListToDataPoints(data)}
+ metricFormatter={metricFormatter}
+ config={{ metric: { label: metricLabel } }}
+ rowLimit={maxExpandedBars}
+ chartConfig={{
+ type: "HORIZONTAL_BAR",
+ row_limit: maxExpandedBars,
+ unit,
+ show_value_labels: true,
+ }}
+ />
+ </div>
+ </div>
+ </div>
+ );
+}