Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(Table): handle empty data array without crashing

Steven Enamakel28ddedc3992c
diff --git a/app/src/components/ui/Table.tsx b/app/src/components/ui/Table.tsx
index 43d07d2585..1ad9add25d 100644
--- a/app/src/components/ui/Table.tsx
+++ b/app/src/components/ui/Table.tsx
@@ -4,16 +4,50 @@ import { cn } from '../../lib/cn';
/**
* Radix has no Table primitive, so these are thin semantic wrappers that give
- * the eleven hand-rolled tables in the app one shared look and — more
- * usefully — one place that gets horizontal overflow right. A wide table that
- * cannot scroll inside its own container is what makes a whole page scroll
- * sideways.
+ * the app's hand-rolled tables one shared look and — more usefully — one place
+ * that gets horizontal overflow and sticky headers right.
+ *
+ * Two layout decisions here are load-bearing; both exist because a sticky
+ * header is impossible without them.
+ *
+ * **`border-separate`, not `border-collapse`.** Under `border-collapse` a
+ * border belongs to the *table grid*, not to the cell that declared it, so a
+ * `position: sticky` header cell scrolls its own bottom border away and the
+ * header ends up floating over the rows with nothing under it. With
+ * `border-separate border-spacing-0` the border is painted by the cell and
+ * travels with it. The visual result is identical for the
+ * one-hairline-per-row design every table here uses.
+ *
+ * **Row borders live on the cells** (`[&>*]:border-b` on the row) for the same
+ * reason: `border-separate` does not paint borders declared on a `<tr>` at all.
+ *
+ * `Table` wraps itself in a horizontal scroller by default so a wide table
+ * scrolls inside its own container instead of making the page scroll sideways.
+ * That wrapper is the thing a sticky header must NOT be inside — see
+ * `containerClassName`.
*/
-export const Table = ({ className, ...rest }: ComponentPropsWithoutRef<'table'>) => (
- <div className="w-full overflow-x-auto">
+export const Table = ({
+ className,
+ containerClassName,
+ ...rest
+}: ComponentPropsWithoutRef<'table'> & {
+ /**
+ * Classes for the wrapper `div`, replacing the default `overflow-x-auto`.
+ *
+ * Pass `"w-full"` (no overflow) when an ancestor already owns scrolling and
+ * the header is sticky. CSS forces `overflow-y` to `auto` whenever
+ * `overflow-x` is not `visible`, so the default wrapper silently becomes its
+ * own scroll container, sized to its content — and a `sticky top-0` header
+ * inside it is then stuck to a box that never scrolls, which is why it looks
+ * like `sticky` "doesn't work" while every class is spelled correctly.
+ * {@link DataTable} does exactly this.
+ */
+ containerClassName?: string;
+}) => (
+ <div className={cn('w-full', containerClassName ?? 'overflow-x-auto')}>
<table
data-slot="table"
- className={cn('w-full caption-bottom border-collapse text-sm', className)}
+ className={cn('w-full caption-bottom border-separate border-spacing-0 text-sm', className)}
{...rest}
/>
</div>
@@ -22,20 +56,24 @@ export const Table = ({ className, ...rest }: ComponentPropsWithoutRef<'table'>)
export const TableHeader = ({ className, ...rest }: ComponentPropsWithoutRef<'thead'>) => (
<thead
data-slot="table-header"
- className={cn('[&_tr]:border-b [&_tr]:border-line', className)}
+ className={cn('[&_tr>*]:border-b [&_tr>*]:border-line', className)}
{...rest}
/>
);
export const TableBody = ({ className, ...rest }: ComponentPropsWithoutRef<'tbody'>) => (
- <tbody data-slot="table-body" className={cn('[&_tr:last-child]:border-0', className)} {...rest} />
+ <tbody
+ data-slot="table-body"
+ className={cn('[&_tr:last-child>*]:border-b-0', className)}
+ {...rest}
+ />
);
export const TableRow = ({ className, ...rest }: ComponentPropsWithoutRef<'tr'>) => (
<tr
data-slot="table-row"
className={cn(
- 'border-b border-line-subtle transition-colors hover:bg-surface-hover',
+ '[&>*]:border-b [&>*]:border-line-subtle transition-colors hover:bg-surface-hover',
className
)}
{...rest}