🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): peek header and tabs keep their layout while loading (#18382)
Trang Nguyen239b50562950
diff --git a/web/src/components/table/peek/peek-observation-detail.tsx b/web/src/components/table/peek/peek-observation-detail.tsxindex e84833d1d2..8f2a7080b0 100644--- a/web/src/components/table/peek/peek-observation-detail.tsx+++ b/web/src/components/table/peek/peek-observation-detail.tsx@@ -40,42 +40,36 @@ export const TablePeekViewObservationDetail = (timestamp,});- const actionProps = trace.data- ? {- trace: trace.data,- traceContext: "peek" as const,- shareUrl: buildTracePath({- projectId: trace.data.projectId,- traceId: trace.data.id,+ const actionProps = {+ trace: trace.data,+ traceContext: "peek" as const,+ shareUrl: traceId+ ? buildTracePath({+ projectId,+ traceId,observationId:typeof router.query.traceId === "string"? peekObservationId: undefined,timestamp:typeof router.query.traceId === "string" ? undefined : timestamp,- }),- timestamp,- onAfterDelete: (deletedTraceId: string) => {- if (shouldClosePeekAfterDelete(traceIdRef.current, deletedTraceId)) {- props.closePeek();- }- },+ })+ : undefined,+ timestamp,+ onAfterDelete: (deletedTraceId: string) => {+ if (shouldClosePeekAfterDelete(traceIdRef.current, deletedTraceId)) {+ props.closePeek();}- : null;+ },+ };return (<TablePeekView{...props}title={traceId}hideExpandToggle- actions={- actionProps ? <TraceDetailActions {...actionProps} /> : undefined- }- actionsMenu={- actionProps ? (- <TraceDetailActions {...actionProps} layout="menu" />- ) : undefined- }+ actions={<TraceDetailActions {...actionProps} />}+ actionsMenu={<TraceDetailActions {...actionProps} layout="menu" />}><TraceDetailBodytrace={trace.data}diff --git a/web/src/components/table/peek/peek-trace-detail.tsx b/web/src/components/table/peek/peek-trace-detail.tsxindex 5cb448054a..dd4d739d9e 100644--- a/web/src/components/table/peek/peek-trace-detail.tsx+++ b/web/src/components/table/peek/peek-trace-detail.tsx@@ -41,37 +41,27 @@ export const TablePeekViewTraceDetail = (timestamp,});- const actionProps = trace.data- ? {- trace: trace.data,- traceContext: "peek" as const,- shareUrl: buildTracePath({- projectId: trace.data.projectId,- traceId: trace.data.id,- timestamp,- }),- timestamp,- onAfterDelete: (deletedTraceId: string) => {- if (shouldClosePeekAfterDelete(peekIdRef.current, deletedTraceId)) {- tablePeekViewProps.closePeek();- }- },+ const actionProps = {+ trace: trace.data,+ traceContext: "peek" as const,+ shareUrl: traceId+ ? buildTracePath({ projectId, traceId, timestamp })+ : undefined,+ timestamp,+ onAfterDelete: (deletedTraceId: string) => {+ if (shouldClosePeekAfterDelete(peekIdRef.current, deletedTraceId)) {+ tablePeekViewProps.closePeek();}- : null;+ },+ };return (<TablePeekView{...tablePeekViewProps}title={traceId}hideExpandToggle- actions={- actionProps ? <TraceDetailActions {...actionProps} /> : undefined- }- actionsMenu={- actionProps ? (- <TraceDetailActions {...actionProps} layout="menu" />- ) : undefined- }+ actions={<TraceDetailActions {...actionProps} />}+ actionsMenu={<TraceDetailActions {...actionProps} layout="menu" />}><TraceDetailBodytrace={trace.data}diff --git a/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx b/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsxindex e6592751ae..5351477fab 100644--- a/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx+++ b/web/src/features/traces/components/ObservationDetailView/components/ObservationDetailViewHeader/ObservationDetailViewHeader.tsx@@ -184,6 +184,14 @@ export const ObservationDetailViewHeader = memo(/>);+ const renderAddToButton = (triggerProps: Record<string, unknown> = {}) => (+ <Button variant="secondary" size="sm" className="gap-1" {...triggerProps}>+ <PlusIcon className="icon-base" />+ <span>Add to</span>+ <DropdownIndicator size="sm" nudge />+ </Button>+ );+return (<div className="@container shrink-0 space-y-2 border-b p-2">{/* Title row with actions */}@@ -342,7 +350,7 @@ export const ObservationDetailViewHeader = memo({/* Action buttons (desktop inline cluster) */}{!isMobile && (<div className="flex h-full flex-wrap content-start items-start justify-start gap-0.5 @2xl:mr-1 @2xl:justify-end">- {observationWithIO && (+ {observationWithIO ? (<ConnectedTraceObservationAddToDropdownMenuControlleranalyticsData={{ source: "TraceDetail", isV4: isV4Enabled }}projectId={projectId}@@ -359,19 +367,12 @@ export const ObservationDetailViewHeader = memo(: undefined}>- {({ getTriggerProps }) => (- <Button- variant="secondary"- size="sm"- className="gap-1"- {...getTriggerProps()}- >- <PlusIcon className="icon-base" />- <span>Add to</span>- <DropdownIndicator size="sm" nudge />- </Button>- )}+ {({ getTriggerProps }) =>+ renderAddToButton(getTriggerProps())+ }</ConnectedTraceObservationAddToDropdownMenuController>+ ) : (+ renderAddToButton({ disabled: true }))}{/* Hide annotation buttons in annotation mode (panel shown separately) */}{!isAnnotationMode && (diff --git a/web/src/features/traces/components/TraceDetailActions.tsx b/web/src/features/traces/components/TraceDetailActions.tsxindex 655293dae1..42baf7dc36 100644--- a/web/src/features/traces/components/TraceDetailActions.tsx+++ b/web/src/features/traces/components/TraceDetailActions.tsx@@ -19,6 +19,19 @@ type TraceDetailData = NonNullable<ReturnType<typeof useTraceDetailData>["data"]>;+type TraceDetailActionsLayout = "toolbar" | "menu";++type TraceDetailActionsProps = {+ /** Undefined while the trace loads: the actions render disabled in place. */+ trace: TraceDetailData | undefined;+ traceContext: "fullscreen" | "peek";+ shareUrl?: string;+ timestamp?: Date;+ deleteRedirectUrl?: string;+ onAfterDelete?: (deletedTraceId: string) => void;+ layout?: TraceDetailActionsLayout;+};+/*** Trace-level header actions shared by the peek and the standalone trace page.*@@ -35,21 +48,56 @@ type TraceDetailData = NonNullable<* is hosted over many different lists, each backed by a different query.*/export function TraceDetailActions({+ trace,+ layout = "toolbar",+ ...props+}: TraceDetailActionsProps) {+ if (!trace) return <DisabledTraceDetailActions layout={layout} />;+ return <LoadedTraceDetailActions trace={trace} layout={layout} {...props} />;+}++function DisabledTraceDetailActions({+ layout,+}: {+ layout: TraceDetailActionsLayout;+}) {+ const downloadIcon = <Download className="icon-base" />;++ if (layout === "menu") {+ return (+ <div className="flex w-full flex-col gap-0.5">+ <HeaderActionMenuRow+ label="Download JSON"+ icon={downloadIcon}+ disabled+ />+ </div>+ );+ }++ return (+ <div className="flex flex-row items-center gap-1">+ <HeaderActionButton label="Download JSON" icon={downloadIcon} disabled />+ <HeaderActionButton+ label="More actions"+ icon={<MoreVertical className="icon-base" />}+ disabled+ />+ </div>+ );+}++function LoadedTraceDetailActions({trace,traceContext,shareUrl,timestamp,deleteRedirectUrl,onAfterDelete,- layout = "toolbar",-}: {+ layout,+}: Omit<TraceDetailActionsProps, "trace" | "layout"> & {trace: TraceDetailData;- traceContext: "fullscreen" | "peek";- shareUrl?: string;- timestamp?: Date;- deleteRedirectUrl?: string;- onAfterDelete?: (deletedTraceId: string) => void;- layout?: "toolbar" | "menu";+ layout: TraceDetailActionsLayout;}) {const shareItems = useShareMenuItems({kind: "trace",diff --git a/web/src/features/traces/components/TraceDetailTabsBarList.tsx b/web/src/features/traces/components/TraceDetailTabsBarList.tsxindex 1264360bc5..b7e2457478 100644--- a/web/src/features/traces/components/TraceDetailTabsBarList.tsx+++ b/web/src/features/traces/components/TraceDetailTabsBarList.tsx@@ -47,17 +47,19 @@ export function TraceDetailTabsBarList({>{/* The triggers stay mounted while the dropdown is shown so theirnatural width remains measurable and the row can come back once- there is room. Hiding them also takes them out of the tab order. */}+ there is room. Hiding them also takes them out of the tab order.+ Until the first measurement neither presentation shows. */}<divref={contentRef}className={cn("flex h-full w-max shrink-0 items-center",- !fits && "invisible absolute",+ fits !== true && "invisible",+ fits === false && "absolute",)}>{triggers}</div>- {!fits && (+ {fits === false && (<TraceDetailTabMenutabs={tabs}selectedTab={selectedTab}diff --git a/web/src/hooks/useFitsAvailableWidth.ts b/web/src/hooks/useFitsAvailableWidth.tsindex 3bb62d1329..cd7d49309b 100644--- a/web/src/hooks/useFitsAvailableWidth.ts+++ b/web/src/hooks/useFitsAvailableWidth.ts@@ -1,4 +1,5 @@import { useLayoutEffect, useRef, useState } from "react";+import { flushSync } from "react-dom";/*** Reports whether the natural width of the element on `contentRef` still fits@@ -7,6 +8,10 @@ import { useLayoutEffect, useRef, useState } from "react";* actually stops fitting, instead of at a fixed breakpoint that has to assume* the widest possible content.*+ * `fits` is undefined until the first measurement, so callers can hold back+ * both presentations instead of painting the wrong one. Every later change is+ * committed before the browser paints, so the swap never flashes.+ ** 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.@@ -21,7 +26,7 @@ export function useFitsAvailableWidth<>() {const availableRef = useRef<TAvailable>(null);const contentRef = useRef<TContent>(null);- const [fits, setFits] = useState(true);+ const [fits, setFits] = useState<boolean>();useLayoutEffect(() => {const available = availableRef.current;@@ -31,19 +36,20 @@ export function useFitsAvailableWidth<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);- };+ // 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.+ const measure = () => content.scrollWidth <= available.clientWidth + 1;- measure();+ setFits(measure());if (typeof ResizeObserver === "undefined") {return;}- const resizeObserver = new ResizeObserver(measure);+ // Resize callbacks run before paint; a synchronous commit keeps it that way.+ const resizeObserver = new ResizeObserver(() => {+ flushSync(() => setFits(measure()));+ });resizeObserver.observe(available);resizeObserver.observe(content);