Skip to content

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

fix(web): unquote media chips and untangle hover overlays in table IO cells (#14761)

Tobias Wochinger8526a43984c5
diff --git a/web/src/components/ui/IOTableCell.clienttest.tsx b/web/src/components/ui/IOTableCell.clienttest.tsx
new file mode 100644
index 0000000000..52dcf8ad33
--- /dev/null
+++ b/web/src/components/ui/IOTableCell.clienttest.tsx
@@ -0,0 +1,195 @@
+import { fireEvent, render, screen } from "@testing-library/react";
+import { IOTableCell } from "@/src/components/ui/IOTableCell";
+import { MarkdownContextProvider } from "@/src/features/theming/useMarkdownContext";
+
+vi.mock("next/router", () => ({
+ useRouter: () => ({ query: {} }),
+}));
+
+vi.mock("posthog-js/react", () => ({
+ usePostHog: () => ({ capture: vi.fn() }),
+}));
+
+vi.mock("@/src/utils/api", () => ({
+ api: {
+ media: {
+ getById: {
+ useQuery: () => ({ isError: false, data: undefined }),
+ },
+ },
+ },
+}));
+
+const MEDIA_REF =
+ "@@@langfuseMedia:type=image/png|id=cc48838a-3da8-4ca4-a007-2cf8df930e69|source=bytes@@@";
+
+const renderCell = (props: {
+ data: unknown;
+ singleLine: boolean;
+ enableExpandOnHover?: boolean;
+}) =>
+ render(
+ <MarkdownContextProvider>
+ <IOTableCell {...props} />
+ </MarkdownContextProvider>,
+ );
+
+/**
+ * Native title tooltips render on top of open popovers (media peek, cell
+ * expand card), so the single-line cell title must yield whenever such a
+ * hover surface supersedes it.
+ */
+describe("IOTableCell native title suppression", () => {
+ it("single-line: drops the cell title while the pointer is over a media chip", () => {
+ const { container } = renderCell({
+ data: `Here is an image: ${MEDIA_REF} — nice.`,
+ singleLine: true,
+ });
+
+ const cell = container.querySelector("[title]")!;
+ expect(cell.getAttribute("title")).toContain("Here is an image");
+
+ fireEvent.pointerOver(screen.getByRole("button", { name: "PNG media" }));
+ expect(cell.getAttribute("title")).toBeNull();
+
+ // moving off the chip back onto cell text restores the title
+ fireEvent.pointerOver(cell);
+ expect(cell.getAttribute("title")).toContain("Here is an image");
+ });
+
+ it("single-line: has no cell title when the expand-on-hover card previews the content", () => {
+ const { container } = renderCell({
+ data: "Langfuse is an open-source LLM engineering platform.",
+ singleLine: true,
+ enableExpandOnHover: true,
+ });
+
+ expect(container.querySelector("[title]")).toBeNull();
+ });
+
+ it("single-line: keeps the cell title otherwise", () => {
+ const text = "Langfuse is an open-source LLM engineering platform.";
+ const { container } = renderCell({ data: text, singleLine: true });
+
+ expect(container.querySelector("[title]")?.getAttribute("title")).toBe(
+ text,
+ );
+ });
+});
+
+/**
+ * Chip quote consistency across row heights: JSON.stringify wraps media
+ * reference strings in quotes — as a lone compact-verbosity value
+ * ('"@@@ref@@@"') and nested inside stringified JSON — so single-line rows
+ * used to render quoted chips while the multi-line JSON view rendered bare
+ * chips. A quote pair directly enclosing a chip is now dropped, so chips
+ * render unquoted at every height; text keeps its existing rendering.
+ */
+describe("IOTableCell media chip rendering", () => {
+ it("single-line: lone JSON-encoded media ref renders as a bare chip", () => {
+ const { container } = renderCell({
+ data: JSON.stringify(MEDIA_REF),
+ singleLine: true,
+ });
+
+ expect(
+ screen.getByRole("button", { name: "PNG media" }),
+ ).toBeInTheDocument();
+ expect(container.textContent).not.toContain('"');
+ });
+
+ it("multi-line: lone JSON-encoded media ref renders as a bare chip", () => {
+ const { container } = renderCell({
+ data: JSON.stringify(MEDIA_REF),
+ singleLine: false,
+ });
+
+ expect(
+ screen.getByRole("button", { name: "PNG media" }),
+ ).toBeInTheDocument();
+ expect(container.textContent).not.toContain('"');
+ });
+
+ it("multi-line: bare media ref string renders as an unquoted chip", () => {
+ const { container } = renderCell({ data: MEDIA_REF, singleLine: false });
+
+ expect(
+ screen.getByRole("button", { name: "PNG media" }),
+ ).toBeInTheDocument();
+ expect(container.textContent).not.toContain('"');
+ });
+
+ it("single-line: media chip nested in JSON drops its enclosing quote pair", () => {
+ const { container } = renderCell({
+ data: { image: MEDIA_REF },
+ singleLine: true,
+ });
+
+ expect(
+ screen.getByRole("button", { name: "PNG media" }),
+ ).toBeInTheDocument();
+ expect(container.textContent).toContain('"image": PNG');
+ expect(container.textContent).not.toContain('"PNG"');
+ });
+
+ it("single-line: adjacent media refs in an array each drop their quote pair", () => {
+ const { container } = renderCell({
+ data: [MEDIA_REF, MEDIA_REF],
+ singleLine: true,
+ });
+
+ expect(screen.getAllByRole("button", { name: "PNG media" })).toHaveLength(
+ 2,
+ );
+ expect(container.textContent).not.toContain('"');
+ });
+
+ it("single-line: media ref embedded in longer text renders as chip within the text", () => {
+ const { container } = renderCell({
+ data: `Here is an image: ${MEDIA_REF} — nice.`,
+ singleLine: true,
+ });
+
+ expect(
+ screen.getByRole("button", { name: "PNG media" }),
+ ).toBeInTheDocument();
+ expect(container.textContent).toContain("Here is an image: PNG — nice.");
+ });
+
+ it("single-line: top-level plain text renders unquoted", () => {
+ const text = "Langfuse is an open-source AI engineering platform";
+ const { container } = renderCell({ data: text, singleLine: true });
+
+ expect(container.textContent).toContain(text);
+ expect(container.textContent).not.toContain('"');
+ });
+
+ it("multi-line: object data still renders as a JSON tree", () => {
+ const { container } = renderCell({
+ data: { foo: "bar" },
+ singleLine: false,
+ });
+
+ expect(container.textContent).toContain("foo");
+ expect(container.textContent).toContain("bar");
+ });
+
+ it("multi-line: stringified JSON still deep-parses into a JSON tree", () => {
+ const { container } = renderCell({
+ data: '{"foo":"bar"}',
+ singleLine: false,
+ });
+
+ expect(container.textContent).toContain("foo");
+ expect(container.textContent).toContain("bar");
+ });
+
+ it("multi-line: long content is truncated", () => {
+ const { container } = renderCell({
+ data: "x".repeat(10_050),
+ singleLine: false,
+ });
+
+ expect(container.textContent).toContain("truncated");
+ });
+});
diff --git a/web/src/components/ui/IOTableCell.tsx b/web/src/components/ui/IOTableCell.tsx
index 282e91fb76..bd7e5ab232 100644
--- a/web/src/components/ui/IOTableCell.tsx
+++ b/web/src/components/ui/IOTableCell.tsx
@@ -7,7 +7,7 @@ import {
import { splitStringByMediaReferences } from "@/src/components/ui/media/mediaUtils";
import { JsonMediaTag } from "@/src/components/ui/media/JsonMediaTag";
import { cn } from "@/src/utils/tailwind";
-import { memo } from "react";
+import { memo, useRef, useState } from "react";
import {
HoverCard,
HoverCardContent,
@@ -23,12 +23,38 @@ const ioTableCellPaddingClassNames: Record<IOTableCellPadding, string> = {
};
function renderStringWithMediaReferences(value: string) {
- const segments = splitStringByMediaReferences(value);
+ // Copy the segments: the quote-trim below mutates `value` in place, and the
+ // originals belong to splitStringByMediaReferences (unsafe to mutate if it
+ // ever memoizes its result).
+ const segments = splitStringByMediaReferences(value).map((segment) => ({
+ ...segment,
+ }));
if (segments.length === 1 && segments[0]?.type === "text") {
return value;
}
+ // JSON.stringify wraps media reference strings in quotes (both nested in
+ // stringified JSON and as a lone compact-verbosity value), which would
+ // render as a quoted chip — while the multi-line JSON view shows a bare
+ // chip. Drop a quote pair that directly encloses a chip; the escaped-quote
+ // check leaves a literal \" in user text alone.
+ segments.forEach((segment, index) => {
+ if (segment.type !== "media") return;
+ const prev = segments[index - 1];
+ const next = segments[index + 1];
+ if (
+ prev?.type === "text" &&
+ next?.type === "text" &&
+ prev.value.endsWith('"') &&
+ !prev.value.endsWith('\\"') &&
+ next.value.startsWith('"')
+ ) {
+ prev.value = prev.value.slice(0, -1);
+ next.value = next.value.slice(1);
+ }
+ });
+
return segments.map((segment, index) =>
segment.type === "media" ? (
<JsonMediaTag
@@ -46,16 +72,24 @@ const IOTableCellContent = ({
singleLine,
className,
padding,
+ suppressTitle = false,
}: {
data: unknown;
singleLine: boolean;
className?: string;
padding: IOTableCellPadding;
+ suppressTitle?: boolean;
}) => {
const stringifiedJson =
data !== null && data !== undefined ? stringifyJsonNode(data) : undefined;
const paddingClassName = ioTableCellPaddingClassNames[padding];
+ // Native title tooltips render on top of open popovers, so the single-line
+ // title is dropped whenever a hover surface supersedes it: entirely when the
+ // cell has an expand-on-hover card (which previews the same content), and
+ // while the pointer is over a media chip (which has its own hover peek).
+ const [isPointerOverMediaTag, setIsPointerOverMediaTag] = useState(false);
+
// perf: truncate to IO_TABLE_CHAR_LIMIT characters as table becomes unresponsive attempting to render large JSONs with high levels of nesting
const shouldTruncate =
stringifiedJson && stringifiedJson.length > IO_TABLE_CHAR_LIMIT;
@@ -71,7 +105,19 @@ const IOTableCellContent = ({
paddingClassName,
className,
)}
- title={singleLineText}
+ title={
+ suppressTitle || isPointerOverMediaTag ? undefined : singleLineText
+ }
+ // With suppressTitle the state cannot affect output, so skip the
+ // handler to avoid re-rendering on every chip-boundary crossing.
+ onPointerOver={
+ suppressTitle
+ ? undefined
+ : (event) =>
+ setIsPointerOverMediaTag(
+ Boolean((event.target as Element).closest("[data-media-tag]")),
+ )
+ }
>
{singleLineText ? renderStringWithMediaReferences(singleLineText) : null}
</div>
@@ -128,6 +174,13 @@ export const IOTableCell = ({
}) => {
const paddingClassName = ioTableCellPaddingClassNames[padding];
+ // Media chips inside the cell carry their own hover peek; opening the
+ // cell-wide expand card on top of it stacks two popovers. Track whether the
+ // pointer is over a chip and keep the expand card closed for that region —
+ // hover a chip for the media peek, hover anywhere else for the full JSON.
+ const [isExpandOpen, setIsExpandOpen] = useState(false);
+ const isPointerOverMediaTag = useRef(false);
+
if (isLoading) {
return (
<JsonSkeleton
@@ -154,14 +207,32 @@ export const IOTableCell = ({
}
return (
- <HoverCard openDelay={700} closeDelay={100}>
+ <HoverCard
+ openDelay={700}
+ closeDelay={100}
+ open={isExpandOpen}
+ onOpenChange={(open) => {
+ if (open && isPointerOverMediaTag.current) return;
+ setIsExpandOpen(open);
+ }}
+ >
<HoverCardTrigger asChild>
- <div className="group/io-cell relative h-full w-full">
+ <div
+ className="group/io-cell relative h-full w-full"
+ onPointerOver={(event) => {
+ const overMediaTag = Boolean(
+ (event.target as Element).closest("[data-media-tag]"),
+ );
+ isPointerOverMediaTag.current = overMediaTag;
+ if (overMediaTag) setIsExpandOpen(false);
+ }}
+ >
<IOTableCellContent
data={data}
singleLine={singleLine}
className={className}
padding={padding}
+ suppressTitle
/>
</div>
</HoverCardTrigger>
diff --git a/web/src/components/ui/media/MediaTag.clienttest.tsx b/web/src/components/ui/media/MediaTag.clienttest.tsx
index 5c1c0e5f81..d2cad15c3d 100644
--- a/web/src/components/ui/media/MediaTag.clienttest.tsx
+++ b/web/src/components/ui/media/MediaTag.clienttest.tsx
@@ -47,6 +47,20 @@ describe("MediaTag", () => {
expect(onOpenChange).toHaveBeenCalledTimes(1);
});
+ it("empties the native title while the peek is open so no tooltip overlaps it", () => {
+ render(<MediaTag contentType="image/png" status="ready" open />);
+
+ const chip = screen.getByRole("button", { name: "PNG media" });
+ expect(chip.querySelector("span")?.getAttribute("title")).toBe("");
+ });
+
+ it("keeps the label title while the peek is closed", () => {
+ render(<MediaTag contentType="image/png" open={false} />);
+
+ const chip = screen.getByRole("button", { name: "PNG media" });
+ expect(chip.querySelector("span")?.getAttribute("title")).toBe("PNG");
+ });
+
it("shows the fallback when resolved image media fails to render", async () => {
render(
<MediaTag
diff --git a/web/src/components/ui/media/MediaTag.tsx b/web/src/components/ui/media/MediaTag.tsx
index e5ef43f903..951bcc5e06 100644
--- a/web/src/components/ui/media/MediaTag.tsx
+++ b/web/src/components/ui/media/MediaTag.tsx
@@ -195,6 +195,10 @@ export const MediaTag = React.forwardRef<HTMLButtonElement, MediaTagProps>(
<button
ref={ref}
type="button"
+ // Marker for containers to detect chip hover via event delegation
+ // (`closest("[data-media-tag]")`): IOTableCell suppresses its
+ // expand-on-hover card and native title while over a chip.
+ data-media-tag=""
aria-label={`${chipLabel} media`}
aria-expanded={isOpen}
className="hover:bg-accent focus-visible:ring-ring bg-background inline-flex h-3.5 max-w-full items-center gap-1 rounded-sm border px-1 py-0 align-middle text-xs leading-none transition-colors focus-visible:ring-2 focus-visible:outline-hidden"
@@ -209,7 +213,10 @@ export const MediaTag = React.forwardRef<HTMLButtonElement, MediaTagProps>(
<KindIcon kind={kind} className="h-2.5 w-2.5 shrink-0" />
<span
className="relative top-0.25 truncate align-baseline font-mono leading-none"
- title={chipLabel}
+ // Empty while the peek is open: a native tooltip would render on
+ // top of the peek. Ancestors with a title still tooltip over the
+ // peek — containers must suppress theirs too (see IOTableCell).
+ title={isOpen ? "" : chipLabel}
>
{chipLabel}
</span>