Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(trace): peek star a11y + delete-after-nav guard (LFE-10535) (#14594)

Nikita Kabardinf82824678f45
diff --git a/web/src/components/star-toggle.clienttest.tsx b/web/src/components/star-toggle.clienttest.tsx
new file mode 100644
index 0000000000..6d4f632612
--- /dev/null
+++ b/web/src/components/star-toggle.clienttest.tsx
@@ -0,0 +1,57 @@
+import { render, screen } from "@testing-library/react";
+
+import { TooltipProvider } from "@/src/components/ui/tooltip";
+import { StarToggle } from "@/src/components/star-toggle";
+
+/**
+ * LFE-10535 (#1/#2): the star button's accessible name, its labeled-menu text,
+ * and its tooltip are all derived from `value`, so a screen reader always hears
+ * the real bookmark state and every text surface stays in sync with the
+ * (optimistic) icon. A stable `data-bookmark-toggle` hook lets the table keep
+ * "click the star without closing the peek" decoupled from the human label.
+ */
+const noop = () => Promise.resolve();
+
+describe("StarToggle accessible name (LFE-10535)", () => {
+ it("announces the bookmark state on the icon button", () => {
+ const { rerender } = render(
+ <StarToggle value={false} isLoading={false} onClick={noop} />,
+ );
+ expect(
+ screen.getByRole("button", { name: "Bookmark" }),
+ ).toBeInTheDocument();
+
+ rerender(<StarToggle value={true} isLoading={false} onClick={noop} />);
+ expect(
+ screen.getByRole("button", { name: "Remove bookmark" }),
+ ).toBeInTheDocument();
+ });
+
+ it("announces the state in the labeled menu item and shows matching text", () => {
+ const { rerender } = render(
+ <StarToggle value={false} isLoading={false} onClick={noop} showLabel />,
+ );
+ expect(screen.getByRole("button", { name: "Bookmark" })).toHaveTextContent(
+ "Bookmark",
+ );
+
+ rerender(
+ <StarToggle value={true} isLoading={false} onClick={noop} showLabel />,
+ );
+ expect(
+ screen.getByRole("button", { name: "Remove bookmark" }),
+ ).toHaveTextContent("Remove bookmark");
+ });
+
+ it("wires the tooltip onto the real focusable button with a stable behaviour hook", () => {
+ render(
+ <TooltipProvider>
+ <StarToggle value={true} isLoading={false} onClick={noop} tooltip />
+ </TooltipProvider>,
+ );
+ // The accessible name lives on the button itself (TooltipTrigger asChild),
+ // not on a wrapping <span> β€” so SR users hear the tooltip.
+ const button = screen.getByRole("button", { name: "Remove bookmark" });
+ expect(button).toHaveAttribute("data-bookmark-toggle");
+ });
+});
diff --git a/web/src/components/star-toggle.tsx b/web/src/components/star-toggle.tsx
index dd134f673f..708535f1af 100644
--- a/web/src/components/star-toggle.tsx
+++ b/web/src/components/star-toggle.tsx
@@ -1,6 +1,11 @@
import { StarIcon } from "lucide-react";
import { Button } from "@/src/components/ui/button";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/src/components/ui/tooltip";
import { api } from "@/src/utils/api";
import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { type RouterInput } from "@/src/utils/types";
@@ -14,7 +19,8 @@ export function StarToggle({
onClick,
size = "icon",
isLoading,
- label,
+ showLabel = false,
+ tooltip = false,
}: {
value: boolean;
disabled?: boolean;
@@ -22,20 +28,34 @@ export function StarToggle({
size?: "icon" | "icon-xs";
isLoading: boolean;
/** When set, render as a full-width labeled menu item instead of an icon. */
- label?: string;
+ showLabel?: boolean;
+ /** When set, wrap the icon button in a hover tooltip announcing the state. */
+ tooltip?: boolean;
}) {
- return (
+ // Single source of truth for the accessible name, the menu label, AND the
+ // tooltip β€” all derived from `value`, so an optimistic flip updates the icon
+ // and every text surface together, and a screen reader always hears the real
+ // state in both the toolbar and the menu (LFE-10535).
+ const stateLabel = value ? "Remove bookmark" : "Bookmark";
+
+ const button = (
<Button
variant="ghost"
- size={label ? "sm" : size}
- className={label ? "w-full justify-start gap-2 font-normal" : undefined}
+ size={showLabel ? "sm" : size}
+ className={
+ showLabel ? "w-full justify-start gap-2 font-normal" : undefined
+ }
onClick={(e) => {
e.stopPropagation();
onClick(!value);
}}
disabled={disabled}
loading={isLoading}
- aria-label="bookmark"
+ aria-label={stateLabel}
+ // Stable behaviour hook (decoupled from the human-facing label): the
+ // table marks this selector as "don't close the peek" so you can bookmark
+ // a row without dismissing the open peek.
+ data-bookmark-toggle="true"
>
<StarIcon
className="h-4 w-4"
@@ -43,9 +63,20 @@ export function StarToggle({
stroke={value ? "#ca8a04" : "currentColor"}
strokeWidth={2}
/>
- {label ? <span className="text-sm">{label}</span> : null}
+ {showLabel ? <span className="text-sm">{stateLabel}</span> : null}
</Button>
);
+
+ if (!tooltip) return button;
+
+ // TooltipTrigger asChild wraps the real <Button> (not a <span>), so Radix puts
+ // aria-describedby on the focusable control and SR users hear the tooltip.
+ return (
+ <Tooltip>
+ <TooltipTrigger asChild>{button}</TooltipTrigger>
+ <TooltipContent>{stateLabel}</TooltipContent>
+ </Tooltip>
+ );
}
// use by the trace table
@@ -131,13 +162,17 @@ export function StarTraceDetailsToggle({
traceId,
value,
size = "icon",
- label,
+ showLabel = false,
+ tooltip = false,
}: {
projectId: string;
traceId: string;
value: boolean;
size?: "icon" | "icon-xs";
- label?: string;
+ /** Render as a full-width labeled menu item (label tracks the optimistic state). */
+ showLabel?: boolean;
+ /** Wrap the icon button in a hover tooltip announcing the optimistic state. */
+ tooltip?: boolean;
}) {
const utils = api.useUtils();
const hasAccess = useHasProjectAccess({
@@ -170,7 +205,8 @@ export function StarTraceDetailsToggle({
<StarToggle
value={optimisticValue}
size={size}
- label={label}
+ showLabel={showLabel}
+ tooltip={tooltip}
disabled={!hasAccess}
isLoading={isLoading}
onClick={(nextValue) => {
diff --git a/web/src/components/table/peek.tsx b/web/src/components/table/peek.tsx
index c563c9bb01..75f43f83f7 100644
--- a/web/src/components/table/peek.tsx
+++ b/web/src/components/table/peek.tsx
@@ -128,6 +128,17 @@ export const shouldKeepPeekOpenOnOutsideInteraction = (
);
};
+/**
+ * After an in-flight delete resolves, only close the peek if it STILL shows the
+ * trace that was deleted. Deleting trace A then K/J-navigating to trace B before
+ * the mutation settles must leave B's peek open β€” A's stale `closePeek` callback
+ * would otherwise clear the (now-B) peek param and dismiss it (LFE-10535).
+ */
+export const shouldClosePeekAfterDelete = (
+ currentPeekTraceId: string | undefined,
+ deletedTraceId: string,
+): boolean => currentPeekTraceId === deletedTraceId;
+
function TablePeekViewComponent(props: TablePeekViewProps) {
const { title, children } = props;
const router = useRouter();
diff --git a/web/src/components/table/peek/outsideInteraction.clienttest.tsx b/web/src/components/table/peek/outsideInteraction.clienttest.tsx
index 37f3457a78..232e988c29 100644
--- a/web/src/components/table/peek/outsideInteraction.clienttest.tsx
+++ b/web/src/components/table/peek/outsideInteraction.clienttest.tsx
@@ -20,7 +20,7 @@ function targetWith(
return el;
}
-const IGNORED = ['[role="checkbox"]', '[aria-label="bookmark"]'];
+const IGNORED = ['[role="checkbox"]', "[data-bookmark-toggle]"];
describe("shouldKeepPeekOpenOnOutsideInteraction", () => {
afterEach(() => {
@@ -60,7 +60,7 @@ describe("shouldKeepPeekOpenOnOutsideInteraction", () => {
it("keeps open for a table-configured ignoredSelector", () => {
expect(
shouldKeepPeekOpenOnOutsideInteraction(
- targetWith({ "aria-label": "bookmark" }),
+ targetWith({ "data-bookmark-toggle": "true" }),
IGNORED,
),
).toBe(true);
diff --git a/web/src/components/table/peek/peek-observation-detail.tsx b/web/src/components/table/peek/peek-observation-detail.tsx
index 30eb82df11..1f90eba618 100644
--- a/web/src/components/table/peek/peek-observation-detail.tsx
+++ b/web/src/components/table/peek/peek-observation-detail.tsx
@@ -1,4 +1,7 @@
-import { TablePeekView } from "@/src/components/table/peek";
+import {
+ TablePeekView,
+ shouldClosePeekAfterDelete,
+} from "@/src/components/table/peek";
import { usePeekData } from "@/src/components/table/peek/hooks/usePeekData";
import {
TraceDetailBody,
@@ -6,6 +9,7 @@ import {
} from "@/src/components/trace/TraceDetailBody";
import { TraceDetailActions } from "@/src/components/trace/TraceDetailActions";
import { useRouter } from "next/router";
+import { useRef } from "react";
export const TablePeekViewObservationDetail = (
props: Omit<
@@ -29,6 +33,12 @@ export const TablePeekViewObservationDetail = (
const traceId = router.query.traceId as string | undefined;
+ // Live handle on the peeked observation's trace id: an in-flight delete that
+ // resolves after K/J-navigation reads the CURRENT trace here, so it only
+ // closes the peek when it still shows the trace that was deleted (LFE-10535).
+ const traceIdRef = useRef(traceId);
+ traceIdRef.current = traceId;
+
const trace = usePeekData({
projectId,
traceId,
@@ -43,7 +53,11 @@ export const TablePeekViewObservationDetail = (
isPublic: trace.data.public,
name: trace.data.name,
timestamp,
- onAfterDelete: props.closePeek,
+ onAfterDelete: (deletedTraceId: string) => {
+ if (shouldClosePeekAfterDelete(traceIdRef.current, deletedTraceId)) {
+ props.closePeek();
+ }
+ },
}
: null;
diff --git a/web/src/components/table/peek/peek-trace-detail.tsx b/web/src/components/table/peek/peek-trace-detail.tsx
index f2510bc308..c4227c61dd 100644
--- a/web/src/components/table/peek/peek-trace-detail.tsx
+++ b/web/src/components/table/peek/peek-trace-detail.tsx
@@ -1,10 +1,14 @@
import { usePeekData } from "@/src/components/table/peek/hooks/usePeekData";
import { useRouter } from "next/router";
+import { useRef } from "react";
import {
TraceDetailBody,
traceDetailTitle,
} from "@/src/components/trace/TraceDetailBody";
-import { TablePeekView } from "@/src/components/table/peek";
+import {
+ TablePeekView,
+ shouldClosePeekAfterDelete,
+} from "@/src/components/table/peek";
import { TraceDetailActions } from "@/src/components/trace/TraceDetailActions";
export const TablePeekViewTraceDetail = (
@@ -21,6 +25,12 @@ export const TablePeekViewTraceDetail = (
const peekId = router.query.peek as string | undefined;
const timestampParam = router.query.timestamp as string | undefined;
+ // Live handle on the peeked trace id: an in-flight delete that resolves after
+ // K/J-navigation reads the CURRENT peek here (not the stale value captured
+ // when the delete was fired), so it only closes the peek it actually deleted.
+ const peekIdRef = useRef(peekId);
+ peekIdRef.current = peekId;
+
// Decode the timestamp parameter before parsing as Date
// This handles cases where the timestamp might be URL-encoded
const timestamp = timestampParam
@@ -41,7 +51,11 @@ export const TablePeekViewTraceDetail = (
isPublic: trace.data.public,
name: trace.data.name,
timestamp,
- onAfterDelete: props.closePeek,
+ onAfterDelete: (deletedTraceId: string) => {
+ if (shouldClosePeekAfterDelete(peekIdRef.current, deletedTraceId)) {
+ props.closePeek();
+ }
+ },
}
: null;
diff --git a/web/src/components/table/peek/peekDeleteGuard.clienttest.tsx b/web/src/components/table/peek/peekDeleteGuard.clienttest.tsx
new file mode 100644
index 0000000000..4351dd599f
--- /dev/null
+++ b/web/src/components/table/peek/peekDeleteGuard.clienttest.tsx
@@ -0,0 +1,22 @@
+import { describe, expect, it } from "vitest";
+
+import { shouldClosePeekAfterDelete } from "@/src/components/table/peek";
+
+/**
+ * LFE-10535 (#3): deleting trace A then K/J-navigating to trace B before the
+ * delete resolves must NOT close B's peek. The peek closes on a successful
+ * delete only while it still shows the trace that was deleted.
+ */
+describe("shouldClosePeekAfterDelete (LFE-10535)", () => {
+ it("closes when the peek still shows the deleted trace", () => {
+ expect(shouldClosePeekAfterDelete("trace-a", "trace-a")).toBe(true);
+ });
+
+ it("keeps the peek open when it moved on to another trace", () => {
+ expect(shouldClosePeekAfterDelete("trace-b", "trace-a")).toBe(false);
+ });
+
+ it("does not close when the peek is already gone", () => {
+ expect(shouldClosePeekAfterDelete(undefined, "trace-a")).toBe(false);
+ });
+});
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index 900137b33a..c088aaee82 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -1307,7 +1307,9 @@ export default function TracesTable({
itemType: "TRACE" as const,
detailNavigationKey: detailPageListKeys.traces,
peekEventOptions: {
- ignoredSelectors: ['[role="checkbox"]', '[aria-label="bookmark"]'],
+ // Stable hook (decoupled from the star's state-aware aria-label) so
+ // clicking a row's bookmark toggles it without dismissing the peek.
+ ignoredSelectors: ['[role="checkbox"]', "[data-bookmark-toggle]"],
},
...peekNavigationProps,
};
diff --git a/web/src/components/trace/TraceDetailActions.tsx b/web/src/components/trace/TraceDetailActions.tsx
index 2d4d86155a..65dad74301 100644
--- a/web/src/components/trace/TraceDetailActions.tsx
+++ b/web/src/components/trace/TraceDetailActions.tsx
@@ -2,11 +2,6 @@ import { api } from "@/src/utils/api";
import { StarTraceDetailsToggle } from "@/src/components/star-toggle";
import { PublishTraceSwitch } from "@/src/components/publish-object-switch";
import { DeleteTraceButton } from "@/src/components/deleteButton";
-import {
- Tooltip,
- TooltipContent,
- TooltipTrigger,
-} from "@/src/components/ui/tooltip";
/**
* Trace-level header actions (star / publish / delete) shared by the peek and
@@ -22,10 +17,12 @@ import {
* from an observation/event row β€” the surface shows that trace). Behavior
* differs only by surface:
* - **page**: pass `deleteRedirectUrl` β†’ navigates to the list after delete.
- * - **peek**: pass `onAfterDelete` (e.g. `closePeek`) β†’ closes in place. We
- * invalidate broadly because the peek is hosted over many different lists
- * (traces, observations, events, sessions, experiments, datasets), each
- * backed by a different query β€” so the deleted row disappears everywhere.
+ * - **peek**: pass `onAfterDelete` (e.g. `closePeek`) β†’ closes in place. It
+ * receives the deleted trace id so the peek can stay open if K/J-navigation
+ * already moved on to another trace (LFE-10535). We invalidate broadly
+ * because the peek is hosted over many different lists (traces, observations,
+ * events, sessions, experiments, datasets), each backed by a different query
+ * β€” so the deleted row disappears everywhere.
*/
export function TraceDetailActions({
traceId,
@@ -46,7 +43,7 @@ export function TraceDetailActions({
name?: string | null;
timestamp?: Date;
deleteRedirectUrl?: string;
- onAfterDelete?: () => void;
+ onAfterDelete?: (deletedTraceId: string) => void;
size?: "icon" | "icon-xs";
layout?: "toolbar" | "menu";
}) {
@@ -55,10 +52,12 @@ export function TraceDetailActions({
// The page path navigates away (redirectUrl) and never calls this. The peek
// path is hosted over many different lists, so invalidate all queries to
- // refresh whichever list is behind the peek, then close it.
+ // refresh whichever list is behind the peek, then close it. We hand the
+ // deleted trace id to onAfterDelete so the peek can skip closing when it has
+ // already navigated to a different trace (LFE-10535).
const onDeleteInvalidate = () => {
utils.invalidate();
- onAfterDelete?.();
+ onAfterDelete?.(traceId);
};
if (isMenu) {
@@ -68,7 +67,7 @@ export function TraceDetailActions({
projectId={projectId}
traceId={traceId}
value={bookmarked}
- label={bookmarked ? "Remove bookmark" : "Bookmark"}
+ showLabel
/>
<PublishTraceSwitch
projectId={projectId}
@@ -93,24 +92,16 @@ export function TraceDetailActions({
return (
<div className="flex flex-row items-center gap-1">
- {/* Star/Share are plain icon buttons without their own tooltip, so wrap
- them (delete's IconOnlyButton already has one). The span is the
- tooltip trigger; the control inside keeps its own click behavior. */}
- <Tooltip>
- <TooltipTrigger asChild>
- <span className="flex">
- <StarTraceDetailsToggle
- projectId={projectId}
- traceId={traceId}
- value={bookmarked}
- size={size}
- />
- </span>
- </TooltipTrigger>
- <TooltipContent>
- {bookmarked ? "Remove bookmark" : "Bookmark"}
- </TooltipContent>
- </Tooltip>
+ {/* The star owns its tooltip (composed onto the real button, so the
+ aria-describedby lands on the focusable control) and drives its label
+ from the optimistic state β€” see StarToggle. */}
+ <StarTraceDetailsToggle
+ projectId={projectId}
+ traceId={traceId}
+ value={bookmarked}
+ size={size}
+ tooltip
+ />
<PublishTraceSwitch
projectId={projectId}
traceId={traceId}