Skip to content

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

fix(tracing): collapse detail tabs on measured width, not a fixed breakpoint (#18175)

Der Gerät712dd47f1b42
diff --git a/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx b/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx
index d70969ebf1..89ea111019 100644
--- a/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx
+++ b/web/src/features/traces/components/ObservationDetailView/ConnectedObservationDetailView.tsx
@@ -30,7 +30,6 @@ import { Tabs } from "@/src/components/design-system/Tabs/Tabs";
import {
TabsBar,
TabsBarContent,
- TabsBarList,
TabsBarTrigger,
} from "@/src/components/ui/tabs-bar";
import {
@@ -45,7 +44,7 @@ import {
useCommentedPaths,
} from "@/src/features/comments";
import { useRouter } from "next/router";
-import { TraceDetailTabMenu } from "../TraceDetailTabMenu";
+import { TraceDetailTabsBarList } from "../TraceDetailTabsBarList";
import { ScoresTable } from "@/src/features/scores";
import { getMostRecentCorrection } from "@/src/features/corrections";
import { useJsonExpansion } from "@/src/features/traces/contexts/JsonExpansionContext";
@@ -384,132 +383,137 @@ export function ConnectedObservationDetailView({
<TabsBar
value={selectedTab}
- className="@container/detailtabs flex min-h-0 flex-1 flex-col overflow-hidden"
+ className="flex min-h-0 flex-1 flex-col overflow-hidden"
onValueChange={(value) => setSelectedTab(value as DetailTab)}
>
<TooltipProvider>
- <TabsBarList className="shrink-0">
- <div className="shrink-0 @min-[680px]/detailtabs:hidden">
- <TraceDetailTabMenu
- selectedTab={selectedTab}
- onSelect={setSelectedTab}
- tabs={[
- "preview",
- ...(showMessagesTab ? ["messages" as const] : []),
- "attributes",
- ...(showScoresTab ? ["scores" as const] : []),
- ...(showLogViewTab ? ["log" as const] : []),
- ]}
- />
- </div>
- <div className="hidden h-full shrink-0 @min-[680px]/detailtabs:contents">
- <TabsBarTrigger value="preview">Preview</TabsBarTrigger>
- {showMessagesTab && (
- <TabsBarTrigger value="messages" className="gap-1">
- Messages <InternalFeatureBadge />
- </TabsBarTrigger>
- )}
- <TabsBarTrigger value="attributes">Attributes</TabsBarTrigger>
- {showScoresTab ? (
- <TabsBarTrigger value="scores">Scores</TabsBarTrigger>
- ) : null}
- {showLogViewTab ? (
- <TabsBarTrigger value="log">
- <Tooltip>
- <TooltipTrigger asChild>
- <span>Log View</span>
- </TooltipTrigger>
- <TooltipContent className="text-xs">
- {isLogViewVirtualized
- ? `Shows all ${observations.length} observations with virtualization enabled.`
- : "Shows all observations concatenated. Great for quickly scanning through them."}
- </TooltipContent>
- </Tooltip>
- </TabsBarTrigger>
- ) : null}
- </div>
-
- {(selectedTab === "log" ||
- selectedTab === "attributes" ||
- (selectedTab === "preview" && isPrettyViewAvailable)) && (
+ <TraceDetailTabsBarList
+ selectedTab={selectedTab}
+ onSelect={setSelectedTab}
+ tabs={[
+ "preview",
+ ...(showMessagesTab ? ["messages" as const] : []),
+ "attributes",
+ ...(showScoresTab ? ["scores" as const] : []),
+ ...(showLogViewTab ? ["log" as const] : []),
+ ]}
+ triggers={
<>
- <div className="ml-auto h-fit shrink-0 px-2 py-0.5">
- <Tabs
- value={
- selectedTab === "log" && isLogViewVirtualized
- ? "pretty"
- : selectedViewTab
- }
- onValueChange={(value) => {
- if (
- selectedTab === "log" &&
- isLogViewVirtualized &&
- value === "json"
- ) {
- return;
- }
- handleViewTabChange(value);
- }}
- >
- <Tabs.List size="sm">
- <Tabs.Trigger
- value="pretty"
- size="sm"
- label="Formatted"
- />
- {selectedTab === "log" && isLogViewVirtualized ? (
- <HoverCard openDelay={200}>
- <HoverCardTrigger asChild>
- <span>
- <Tabs.Trigger
- value="json"
- size="sm"
- disabled
- label="Raw"
- />
- </span>
- </HoverCardTrigger>
- <HoverCardContent
- align="end"
- className="w-64 text-sm"
- sideOffset={8}
- >
- <p className="font-bold">
- Raw view unavailable
- </p>
- <p className="text-muted-foreground mt-1">
- Disabled for traces with{" "}
- {
- TRACE_VIEW_CONFIG.logView
- .virtualizationThreshold
- }
- + observations to maintain performance.
- </p>
- </HoverCardContent>
- </HoverCard>
- ) : (
- <Tabs.Trigger value="json" size="sm" label="Raw" />
- )}
- </Tabs.List>
- </Tabs>
- </div>
- {selectedViewTab === "json" &&
- selectedTab !== "attributes" &&
- !(selectedTab === "log" && isLogViewVirtualized) && (
- <div className="mr-1 flex items-center gap-1.5">
- <Switch
- size="sm"
- checked={jsonBetaEnabled}
- onCheckedChange={handleBetaToggle}
- />
- <span className="text-muted-foreground text-xs">
- Beta
- </span>
- </div>
- )}
+ <TabsBarTrigger value="preview">Preview</TabsBarTrigger>
+ {showMessagesTab && (
+ <TabsBarTrigger value="messages" className="gap-1">
+ Messages <InternalFeatureBadge />
+ </TabsBarTrigger>
+ )}
+ <TabsBarTrigger value="attributes">
+ Attributes
+ </TabsBarTrigger>
+ {showScoresTab ? (
+ <TabsBarTrigger value="scores">Scores</TabsBarTrigger>
+ ) : null}
+ {showLogViewTab ? (
+ <TabsBarTrigger value="log">
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span>Log View</span>
+ </TooltipTrigger>
+ <TooltipContent className="text-xs">
+ {isLogViewVirtualized
+ ? `Shows all ${observations.length} observations with virtualization enabled.`
+ : "Shows all observations concatenated. Great for quickly scanning through them."}
+ </TooltipContent>
+ </Tooltip>
+ </TabsBarTrigger>
+ ) : null}
</>
- )}
- </TabsBarList>
+ }
+ trailingControls={
+ (selectedTab === "log" ||
+ selectedTab === "attributes" ||
+ (selectedTab === "preview" && isPrettyViewAvailable)) && (
+ <>
+ <div className="ml-auto h-fit shrink-0 px-2 py-0.5">
+ <Tabs
+ value={
+ selectedTab === "log" && isLogViewVirtualized
+ ? "pretty"
+ : selectedViewTab
+ }
+ onValueChange={(value) => {
+ if (
+ selectedTab === "log" &&
+ isLogViewVirtualized &&
+ value === "json"
+ ) {
+ return;
+ }
+ handleViewTabChange(value);
+ }}
+ >
+ <Tabs.List size="sm">
+ <Tabs.Trigger
+ value="pretty"
+ size="sm"
+ label="Formatted"
+ />
+ {selectedTab === "log" && isLogViewVirtualized ? (
+ <HoverCard openDelay={200}>
+ <HoverCardTrigger asChild>
+ <span>
+ <Tabs.Trigger
+ value="json"
+ size="sm"
+ disabled
+ label="Raw"
+ />
+ </span>
+ </HoverCardTrigger>
+ <HoverCardContent
+ align="end"
+ className="w-64 text-sm"
+ sideOffset={8}
+ >
+ <p className="font-bold">
+ Raw view unavailable
+ </p>
+ <p className="text-muted-foreground mt-1">
+ Disabled for traces with{" "}
+ {
+ TRACE_VIEW_CONFIG.logView
+ .virtualizationThreshold
+ }
+ + observations to maintain performance.
+ </p>
+ </HoverCardContent>
+ </HoverCard>
+ ) : (
+ <Tabs.Trigger
+ value="json"
+ size="sm"
+ label="Raw"
+ />
+ )}
+ </Tabs.List>
+ </Tabs>
+ </div>
+ {selectedViewTab === "json" &&
+ selectedTab !== "attributes" &&
+ !(selectedTab === "log" && isLogViewVirtualized) && (
+ <div className="mr-1 flex items-center gap-1.5">
+ <Switch
+ size="sm"
+ checked={jsonBetaEnabled}
+ onCheckedChange={handleBetaToggle}
+ />
+ <span className="text-muted-foreground text-xs">
+ Beta
+ </span>
+ </div>
+ )}
+ </>
+ )
+ }
+ />
</TooltipProvider>
{selectedTab === "messages" && (
diff --git a/web/src/features/traces/components/TraceDetailTabsBarList.clienttest.tsx b/web/src/features/traces/components/TraceDetailTabsBarList.clienttest.tsx
new file mode 100644
index 0000000000..6772740db4
--- /dev/null
+++ b/web/src/features/traces/components/TraceDetailTabsBarList.clienttest.tsx
@@ -0,0 +1,136 @@
+/** @vitest-environment jsdom */
+import { act, cleanup, render, screen } from "@testing-library/react";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+import { TabsBar, TabsBarTrigger } from "@/src/components/ui/tabs-bar";
+
+import { TraceDetailTabsBarList } from "./TraceDetailTabsBarList";
+
+// jsdom has no layout engine, so every width is 0 and the component would
+// always believe the triggers fit. These two widths stand in for the layout the
+// browser would compute: the space left for the triggers next to the trailing
+// controls, and the width the triggers need.
+let availableWidth = 1000;
+let triggersWidth = 400;
+const resizeCallbacks: ResizeObserverCallback[] = [];
+
+function isAvailableElement(element: HTMLElement) {
+ // The measured container is the only element the component puts directly
+ // inside the tab list.
+ return element.parentElement?.getAttribute("role") === "tablist";
+}
+
+function setAvailableWidth(width: number) {
+ availableWidth = width;
+ act(() => {
+ for (const callback of resizeCallbacks) {
+ callback([], {} as ResizeObserver);
+ }
+ });
+}
+
+function renderTabsBar() {
+ return render(
+ <TabsBar value="preview" onValueChange={vi.fn()}>
+ <TraceDetailTabsBarList
+ tabs={["preview", "scores"]}
+ selectedTab="preview"
+ onSelect={vi.fn()}
+ triggers={
+ <>
+ <TabsBarTrigger value="preview">Preview</TabsBarTrigger>
+ <TabsBarTrigger value="scores">Scores</TabsBarTrigger>
+ </>
+ }
+ trailingControls={<div>Trailing</div>}
+ />
+ </TabsBar>,
+ );
+}
+
+beforeEach(() => {
+ availableWidth = 1000;
+ triggersWidth = 400;
+ resizeCallbacks.length = 0;
+
+ vi.stubGlobal(
+ "ResizeObserver",
+ class {
+ constructor(callback: ResizeObserverCallback) {
+ resizeCallbacks.push(callback);
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+
+ Object.defineProperty(HTMLElement.prototype, "clientWidth", {
+ configurable: true,
+ get(this: HTMLElement) {
+ return isAvailableElement(this) ? availableWidth : 0;
+ },
+ });
+ Object.defineProperty(HTMLElement.prototype, "scrollWidth", {
+ configurable: true,
+ get(this: HTMLElement) {
+ const parent = this.parentElement;
+ return parent && isAvailableElement(parent) ? triggersWidth : 0;
+ },
+ });
+});
+
+afterEach(() => {
+ cleanup();
+ vi.unstubAllGlobals();
+ Reflect.deleteProperty(HTMLElement.prototype, "clientWidth");
+ Reflect.deleteProperty(HTMLElement.prototype, "scrollWidth");
+});
+
+describe("TraceDetailTabsBarList", () => {
+ it("shows the tab triggers and no dropdown while they fit", () => {
+ renderTabsBar();
+
+ expect(screen.getByRole("tab", { name: "Preview" })).toBeTruthy();
+ expect(screen.getByRole("tab", { name: "Scores" })).toBeTruthy();
+ expect(screen.queryByRole("button", { name: /Detail view/ })).toBeNull();
+ });
+
+ it("falls back to the dropdown once the triggers no longer fit", () => {
+ triggersWidth = 400;
+ availableWidth = 200;
+ renderTabsBar();
+
+ expect(
+ screen.getByRole("button", { name: "Detail view: Preview" }),
+ ).toBeTruthy();
+ // The triggers have to stay mounted behind the dropdown, otherwise their
+ // natural width is no longer measurable and the bar can never tell that
+ // there is room for them again.
+ expect(screen.getByRole("tab", { name: "Preview" })).toBeTruthy();
+ expect(screen.getByRole("tab", { name: "Scores" })).toBeTruthy();
+ });
+
+ it("restores the tab triggers when space becomes available again", () => {
+ triggersWidth = 400;
+ availableWidth = 200;
+ renderTabsBar();
+
+ expect(
+ screen.getByRole("button", { name: "Detail view: Preview" }),
+ ).toBeTruthy();
+
+ setAvailableWidth(800);
+
+ expect(screen.queryByRole("button", { name: /Detail view/ })).toBeNull();
+ expect(screen.getByRole("tab", { name: "Preview" })).toBeTruthy();
+ });
+
+ it("keeps the triggers when they fit the available width exactly", () => {
+ triggersWidth = 400;
+ availableWidth = 400;
+ renderTabsBar();
+
+ expect(screen.queryByRole("button", { name: /Detail view/ })).toBeNull();
+ });
+});
diff --git a/web/src/features/traces/components/TraceDetailTabsBarList.tsx b/web/src/features/traces/components/TraceDetailTabsBarList.tsx
new file mode 100644
index 0000000000..1264360bc5
--- /dev/null
+++ b/web/src/features/traces/components/TraceDetailTabsBarList.tsx
@@ -0,0 +1,71 @@
+import { type ReactNode } from "react";
+
+import { TabsBarList } from "@/src/components/ui/tabs-bar";
+import { useFitsAvailableWidth } from "@/src/hooks/useFitsAvailableWidth";
+import { cn } from "@/src/utils/tailwind";
+
+import { TraceDetailTabMenu } from "./TraceDetailTabMenu";
+import type { DetailTab } from "../contexts/SelectionContext";
+
+/**
+ * Tab bar for the trace and observation detail panels. Keeps the tab triggers
+ * visible for as long as they fit next to the trailing controls and replaces
+ * them with a dropdown once they stop fitting.
+ *
+ * Which tabs a panel shows depends on the trace, the project role, and the
+ * enabled features, so the row is anywhere between two and five tabs wide. The
+ * swap therefore follows the measured width of the triggers: a fixed panel
+ * width would have to assume the widest tab set and would collapse the narrow
+ * ones while there is still room for them.
+ */
+export function TraceDetailTabsBarList({
+ tabs,
+ selectedTab,
+ onSelect,
+ triggers,
+ trailingControls,
+}: {
+ tabs: DetailTab[];
+ selectedTab: DetailTab;
+ onSelect: (tab: DetailTab) => void;
+ triggers: ReactNode;
+ trailingControls: ReactNode;
+}) {
+ const { availableRef, contentRef, fits } = useFitsAvailableWidth<
+ HTMLDivElement,
+ HTMLDivElement
+ >();
+
+ return (
+ <TabsBarList className="shrink-0">
+ {/* A zero flex basis makes this the row space left over by the trailing
+ controls, so the triggers are compared against the width they can
+ actually occupy without that width depending on them in turn. */}
+ <div
+ ref={availableRef}
+ className="relative flex h-full min-w-0 flex-1 items-center overflow-hidden"
+ >
+ {/* The triggers stay mounted while the dropdown is shown so their
+ natural width remains measurable and the row can come back once
+ there is room. Hiding them also takes them out of the tab order. */}
+ <div
+ ref={contentRef}
+ className={cn(
+ "flex h-full w-max shrink-0 items-center",
+ !fits && "invisible absolute",
+ )}
+ >
+ {triggers}
+ </div>
+ {!fits && (
+ <TraceDetailTabMenu
+ tabs={tabs}
+ selectedTab={selectedTab}
+ onSelect={onSelect}
+ />
+ )}
+ </div>
+ {trailingControls}
+ </TabsBarList>
+ );
+}
diff --git a/web/src/features/traces/components/TraceDetailView/TraceDetailView.tsx b/web/src/features/traces/components/TraceDetailView/TraceDetailView.tsx
index 68086338d9..33138ceb96 100644
--- a/web/src/features/traces/components/TraceDetailView/TraceDetailView.tsx
+++ b/web/src/features/traces/components/TraceDetailView/TraceDetailView.tsx
@@ -8,7 +8,6 @@ import { type WithStringifiedMetadata } from "@/src/utils/clientSideDomainTypes"
import {
TabsBar,
TabsBarContent,
- TabsBarList,
TabsBarTrigger,
} from "@/src/components/ui/tabs-bar";
import { Tabs } from "@/src/components/design-system/Tabs/Tabs";
@@ -69,7 +68,7 @@ import {
} from "@/src/features/feature-flags";
import { useReadPath } from "@/src/features/events";
import { TraceMessagesView } from "../TraceMessagesView/TraceMessagesView";
-import { TraceDetailTabMenu } from "../TraceDetailTabMenu";
+import { TraceDetailTabsBarList } from "../TraceDetailTabsBarList";
export interface TraceDetailViewProps {
trace: Omit<WithStringifiedMetadata<TraceDomain>, "input" | "output"> & {
@@ -287,136 +286,135 @@ export function TraceDetailView({
{/* Tabs section */}
<TabsBar
value={selectedTab}
- className="@container/detailtabs flex min-h-0 flex-1 flex-col overflow-hidden"
+ className="flex min-h-0 flex-1 flex-col overflow-hidden"
onValueChange={handleTabChange}
>
{/* Hide the tabs bar when only Preview remains. */}
{showTabsBar && (
<TooltipProvider>
- <TabsBarList className="shrink-0">
- <div className="shrink-0 @min-[680px]/detailtabs:hidden">
- <TraceDetailTabMenu
- selectedTab={selectedTab}
- onSelect={handleTabChange}
- tabs={[
- "preview",
- ...(showMessagesTab ? ["messages" as const] : []),
- ...(showLogViewTab ? ["log" as const] : []),
- ...(showScoresTab ? ["scores" as const] : []),
- ]}
- />
- </div>
- <div className="hidden h-full shrink-0 @min-[680px]/detailtabs:contents">
- <TabsBarTrigger value="preview">Preview</TabsBarTrigger>
- {showMessagesTab && (
- <TabsBarTrigger value="messages" className="gap-1">
- Messages <InternalFeatureBadge />
- </TabsBarTrigger>
- )}
- {showLogViewTab && (
- <TabsBarTrigger value="log">
- <Tooltip>
- <TooltipTrigger asChild>
- <span>Log View</span>
- </TooltipTrigger>
- <TooltipContent className="text-xs">
- {isLogViewVirtualized
- ? `Shows all ${observations.length} observations with virtualization enabled.`
- : "Shows all observations concatenated. Great for quickly scanning through them."}
- </TooltipContent>
- </Tooltip>
- </TabsBarTrigger>
- )}
- {showScoresTab && (
- <TabsBarTrigger value="scores">Scores</TabsBarTrigger>
- )}
- </div>
-
- {/* View toggle (Formatted/JSON) - show for preview and log tabs when pretty view available */}
- {/* JSON views are disabled for virtualized log view (large traces) */}
- {(selectedTab === "log" ||
- (selectedTab === "preview" && isPrettyViewAvailable)) && (
+ <TraceDetailTabsBarList
+ selectedTab={selectedTab}
+ onSelect={handleTabChange}
+ tabs={[
+ "preview",
+ ...(showMessagesTab ? ["messages" as const] : []),
+ ...(showLogViewTab ? ["log" as const] : []),
+ ...(showScoresTab ? ["scores" as const] : []),
+ ]}
+ triggers={
<>
- <div className="ml-auto h-fit shrink-0 px-2 py-0.5">
- <Tabs
- value={
- selectedTab === "log" && isLogViewVirtualized
- ? "pretty"
- : selectedViewTab
- }
- onValueChange={(value) => {
- // Don't allow JSON views for virtualized log view
- if (
- selectedTab === "log" &&
- isLogViewVirtualized &&
- value === "json"
- ) {
- return;
+ <TabsBarTrigger value="preview">Preview</TabsBarTrigger>
+ {showMessagesTab && (
+ <TabsBarTrigger value="messages" className="gap-1">
+ Messages <InternalFeatureBadge />
+ </TabsBarTrigger>
+ )}
+ {showLogViewTab && (
+ <TabsBarTrigger value="log">
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span>Log View</span>
+ </TooltipTrigger>
+ <TooltipContent className="text-xs">
+ {isLogViewVirtualized
+ ? `Shows all ${observations.length} observations with virtualization enabled.`
+ : "Shows all observations concatenated. Great for quickly scanning through them."}
+ </TooltipContent>
+ </Tooltip>
+ </TabsBarTrigger>
+ )}
+ {showScoresTab && (
+ <TabsBarTrigger value="scores">Scores</TabsBarTrigger>
+ )}
+ </>
+ }
+ trailingControls={
+ /* View toggle (Formatted/JSON) - show for preview and log tabs when pretty view available */
+ /* JSON views are disabled for virtualized log view (large traces) */
+ (selectedTab === "log" ||
+ (selectedTab === "preview" && isPrettyViewAvailable)) && (
+ <>
+ <div className="ml-auto h-fit shrink-0 px-2 py-0.5">
+ <Tabs
+ value={
+ selectedTab === "log" && isLogViewVirtualized
+ ? "pretty"
+ : selectedViewTab
}
- handleViewTabChange(value);
- }}
- >
- <Tabs.List size="sm">
- <Tabs.Trigger
- value="pretty"
- size="sm"
- label="Formatted"
- />
- {selectedTab === "log" && isLogViewVirtualized ? (
- <HoverCard openDelay={200}>
- <HoverCardTrigger asChild>
- <Tabs.Trigger
- value="json"
- size="sm"
- disabled
- label="Raw"
- />
- </HoverCardTrigger>
- <HoverCardContent
- align="end"
- className="w-64 text-sm"
- sideOffset={8}
- >
- <p className="font-bold">
- Raw view unavailable
- </p>
- <p className="text-muted-foreground mt-1">
- Disabled for traces with{" "}
- {
- TRACE_VIEW_CONFIG.logView
- .virtualizationThreshold
- }
- + observations to maintain performance.
- </p>
- </HoverCardContent>
- </HoverCard>
- ) : (
+ onValueChange={(value) => {
+ // Don't allow JSON views for virtualized log view
+ if (
+ selectedTab === "log" &&
+ isLogViewVirtualized &&
+ value === "json"
+ ) {
+ return;
+ }
+ handleViewTabChange(value);
+ }}
+ >
+ <Tabs.List size="sm">
<Tabs.Trigger
- value="json"
+ value="pretty"
size="sm"
- label="Raw"
+ label="Formatted"
/>
- )}
- </Tabs.List>
- </Tabs>
- </div>
- {/* Beta toggle - only show when JSON is selected and not in virtualized log view */}
- {selectedViewTab === "json" &&
- !(selectedTab === "log" && isLogViewVirtualized) && (
- <div className="mr-1 flex items-center gap-1.5">
- <Switch
- size="sm"
- checked={jsonBetaEnabled}
- onCheckedChange={handleBetaToggle}
- />
- <span className="text-muted-foreground text-xs">
- Beta
- </span>
- </div>
- )}
- </>
- )}
- </TabsBarList>
+ {selectedTab === "log" && isLogViewVirtualized ? (
+ <HoverCard openDelay={200}>
+ <HoverCardTrigger asChild>
+ <Tabs.Trigger
+ value="json"
+ size="sm"
+ disabled
+ label="Raw"
+ />
+ </HoverCardTrigger>
+ <HoverCardContent
+ align="end"
+ className="w-64 text-sm"
+ sideOffset={8}
+ >
+ <p className="font-bold">
+ Raw view unavailable
+ </p>
+ <p className="text-muted-foreground mt-1">
+ Disabled for traces with{" "}
+ {
+ TRACE_VIEW_CONFIG.logView
+ .virtualizationThreshold
+ }
+ + observations to maintain performance.
+ </p>
+ </HoverCardContent>
+ </HoverCard>
+ ) : (
+ <Tabs.Trigger
+ value="json"
+ size="sm"
+ label="Raw"
+ />
+ )}
+ </Tabs.List>
+ </Tabs>
+ </div>
+ {/* Beta toggle - only show when JSON is selected and not in virtualized log view */}
+ {selectedViewTab === "json" &&
+ !(selectedTab === "log" && isLogViewVirtualized) && (
+ <div className="mr-1 flex items-center gap-1.5">
+ <Switch
+ size="sm"
+ checked={jsonBetaEnabled}
+ onCheckedChange={handleBetaToggle}
+ />
+ <span className="text-muted-foreground text-xs">
+ Beta
+ </span>
+ </div>
+ )}
+ </>
+ )
+ }
+ />
</TooltipProvider>
)}
diff --git a/web/src/hooks/useFitsAvailableWidth.ts b/web/src/hooks/useFitsAvailableWidth.ts
new file mode 100644
index 0000000000..3bb62d1329
--- /dev/null
+++ b/web/src/hooks/useFitsAvailableWidth.ts
@@ -0,0 +1,54 @@
+import { useLayoutEffect, useRef, useState } from "react";
+
+/**
+ * Reports whether the natural width of the element on `contentRef` still fits
+ * the width available inside the element on `availableRef`. Lets a caller swap
+ * a wide presentation for a compact one at the width where the wide one
+ * actually stops fitting, instead of at a fixed breakpoint that has to assume
+ * the widest possible content.
+ *
+ * The measured content has to stay mounted and sized to its content while the
+ * compact presentation is shown. Once it unmounts its natural width is no
+ * longer observable and the caller can never go back to the wide presentation.
+ *
+ * The available element must not derive its own width from the measured
+ * content, otherwise the two measurements feed back into each other and the
+ * result oscillates. A flex item with a zero flex basis satisfies this.
+ */
+export function useFitsAvailableWidth<
+ TAvailable extends HTMLElement,
+ TContent extends HTMLElement,
+>() {
+ const availableRef = useRef<TAvailable>(null);
+ const contentRef = useRef<TContent>(null);
+ const [fits, setFits] = useState(true);
+
+ useLayoutEffect(() => {
+ const available = availableRef.current;
+ const content = contentRef.current;
+
+ if (!available || !content) {
+ return;
+ }
+
+ const measure = () => {
+ // Sub-pixel layout rounds against the content at the exact boundary, so
+ // spend a pixel of slack rather than collapsing a row that just fits.
+ setFits(content.scrollWidth <= available.clientWidth + 1);
+ };
+
+ measure();
+
+ if (typeof ResizeObserver === "undefined") {
+ return;
+ }
+
+ const resizeObserver = new ResizeObserver(measure);
+ resizeObserver.observe(available);
+ resizeObserver.observe(content);
+
+ return () => resizeObserver.disconnect();
+ }, []);
+
+ return { availableRef, contentRef, fits };
+}