Skip to content

πŸ™Œ OpenHands: AI-Driven Development

feat(frontend): render GFM tables with visible borders in chat messages (#13825)

Vasco Schiavo738e7a983417
diff --git a/frontend/__tests__/components/features/markdown/table.test.tsx b/frontend/__tests__/components/features/markdown/table.test.tsx
new file mode 100644
index 0000000000..32195d34a0
--- /dev/null
+++ b/frontend/__tests__/components/features/markdown/table.test.tsx
@@ -0,0 +1,76 @@
+import { render, screen } from "@testing-library/react";
+import { describe, it, expect } from "vitest";
+import { MarkdownRenderer } from "#/components/features/markdown/markdown-renderer";
+
+const GFM_TABLE = [
+ "| Feature | OpenAI Codex | Claude Code |",
+ "|---------|--------------|-------------|",
+ "| CLI | βœ… | βœ… |",
+ "| Mobile | ❌ | βœ… |",
+].join("\n");
+
+describe("table (markdown)", () => {
+ it("should render a GFM pipe table as a <table> element", () => {
+ render(<MarkdownRenderer>{GFM_TABLE}</MarkdownRenderer>);
+
+ const table = screen.getByRole("table");
+ expect(table).toBeInTheDocument();
+ // border-collapse + border is what makes columns visually separate
+ expect(table).toHaveClass("border-collapse");
+ expect(table).toHaveClass("border");
+ });
+
+ it("should wrap the table in a horizontally scrollable container", () => {
+ const { container } = render(
+ <MarkdownRenderer>{GFM_TABLE}</MarkdownRenderer>,
+ );
+
+ // Wide tables must not break chat layout β€” wrapper enables overflow
+ const wrapper = container.querySelector(".overflow-x-auto");
+ expect(wrapper).not.toBeNull();
+ expect(wrapper?.querySelector("table")).not.toBeNull();
+ });
+
+ it("should render header cells as styled <th> elements", () => {
+ render(<MarkdownRenderer>{GFM_TABLE}</MarkdownRenderer>);
+
+ const headers = screen.getAllByRole("columnheader");
+ expect(headers).toHaveLength(3);
+ expect(headers[0]).toHaveTextContent("Feature");
+ expect(headers[1]).toHaveTextContent("OpenAI Codex");
+ expect(headers[2]).toHaveTextContent("Claude Code");
+ // Padding + border is what was missing before the fix
+ headers.forEach((h) => {
+ expect(h).toHaveClass("border");
+ expect(h).toHaveClass("px-3");
+ expect(h).toHaveClass("py-2");
+ });
+ });
+
+ it("should render body cells as styled <td> elements", () => {
+ render(<MarkdownRenderer>{GFM_TABLE}</MarkdownRenderer>);
+
+ const cells = screen.getAllByRole("cell");
+ expect(cells).toHaveLength(6);
+ expect(cells[0]).toHaveTextContent("CLI");
+ expect(cells[3]).toHaveTextContent("Mobile");
+ cells.forEach((c) => {
+ expect(c).toHaveClass("border");
+ expect(c).toHaveClass("px-3");
+ expect(c).toHaveClass("py-2");
+ });
+ });
+
+ it("should not render table markdown as plain paragraph text", () => {
+ // Regression guard: before the fix, missing component overrides made the
+ // table render with no visible borders/padding so columns looked like
+ // space-separated text. Ensure a real <table> exists now.
+ const { container } = render(
+ <MarkdownRenderer>{GFM_TABLE}</MarkdownRenderer>,
+ );
+
+ expect(container.querySelectorAll("table")).toHaveLength(1);
+ expect(container.querySelectorAll("th")).toHaveLength(3);
+ expect(container.querySelectorAll("td")).toHaveLength(6);
+ });
+});
diff --git a/frontend/src/components/features/markdown/markdown-renderer.tsx b/frontend/src/components/features/markdown/markdown-renderer.tsx
index 15a6db26ca..64f6ad7448 100644
--- a/frontend/src/components/features/markdown/markdown-renderer.tsx
+++ b/frontend/src/components/features/markdown/markdown-renderer.tsx
@@ -6,6 +6,7 @@ import { ul, ol } from "./list";
import { paragraph } from "./paragraph";
import { anchor } from "./anchor";
import { h1, h2, h3, h4, h5, h6 } from "./headings";
+import { table, th, td } from "./table";
interface MarkdownRendererProps {
/**
@@ -55,6 +56,9 @@ export function MarkdownRenderer({
code,
ul,
ol,
+ table,
+ th,
+ td,
...(includeStandard && {
a: anchor,
p: paragraph,
diff --git a/frontend/src/components/features/markdown/table.tsx b/frontend/src/components/features/markdown/table.tsx
new file mode 100644
index 0000000000..0cb7c51bbd
--- /dev/null
+++ b/frontend/src/components/features/markdown/table.tsx
@@ -0,0 +1,43 @@
+import React from "react";
+import { ExtraProps } from "react-markdown";
+
+// Custom component to render <table> in markdown
+export function table({
+ children,
+}: React.ClassAttributes<HTMLTableElement> &
+ React.TableHTMLAttributes<HTMLTableElement> &
+ ExtraProps) {
+ return (
+ <div className="my-4 w-full overflow-x-auto">
+ <table className="w-full border-collapse border border-neutral-600 text-sm">
+ {children}
+ </table>
+ </div>
+ );
+}
+
+// Custom component to render <th> in markdown
+export function th({
+ children,
+}: React.ClassAttributes<HTMLTableCellElement> &
+ React.ThHTMLAttributes<HTMLTableCellElement> &
+ ExtraProps) {
+ return (
+ <th className="border border-neutral-600 bg-neutral-800 px-3 py-2 text-left font-semibold text-white">
+ {children}
+ </th>
+ );
+}
+
+// Custom component to render <td> in markdown
+export function td({
+ children,
+}: React.ClassAttributes<HTMLTableCellElement> &
+ React.TdHTMLAttributes<HTMLTableCellElement> &
+ ExtraProps) {
+ return (
+ <td className="border border-neutral-600 px-3 py-2 align-top">
+ {children}
+ </td>
+ );
+}