:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(quill): re-render datatable rows when row selection changes (#130338)
Fernando Gomesc00e042ce35f
diff --git a/packages/quill/packages/components/src/data-table.test.tsx b/packages/quill/packages/components/src/data-table.test.tsxindex 382c6478a037..4085590ad769 100644--- a/packages/quill/packages/components/src/data-table.test.tsx+++ b/packages/quill/packages/components/src/data-table.test.tsx@@ -41,6 +41,24 @@ describe('DataTable', () => {expect(onRowClick).toHaveBeenCalledWith(data[0])})+ it('shows a selection made from a cell on the row', () => {+ const columns: ColumnDef<TestRow>[] = [+ {+ id: 'select',+ cell: ({ row }) => (+ <input type="checkbox" checked={row.getIsSelected()} onChange={() => row.toggleSelected()} />+ ),+ },+ { accessorKey: 'name', header: 'Name' },+ ]+ const { container } = render(<DataTable columns={columns} data={data} />)++ fireEvent.click(screen.getByRole('checkbox'))++ expect(container.querySelector('tbody tr')!.getAttribute('data-state')).toBe('selected')+ expect((screen.getByRole('checkbox') as HTMLInputElement).checked).toBe(true)+ })+it('applies a row class name per row', () => {const columns: ColumnDef<TestRow>[] = [{ accessorKey: 'name', header: 'Name' }]const { container } = render(diff --git a/packages/quill/packages/components/src/data-table.tsx b/packages/quill/packages/components/src/data-table.tsxindex 483b109dd892..8d83c6a68d0d 100644--- a/packages/quill/packages/components/src/data-table.tsx+++ b/packages/quill/packages/components/src/data-table.tsx@@ -2,6 +2,7 @@ import {type ColumnDef,type ColumnSizingState,type PaginationState,+ type RowSelectionState,type Row,type RowData,type Header,@@ -354,6 +355,8 @@ function DataTableHead<TData>({// Memoized so that a resize, which ends by setting a width on the table, does not render every row again. For the same// reason, a caller with its own state should keep `columns`, `onRowClick`, `rowClassName` and `empty` stable between renders.+// TanStack keeps `rows` the same array when only the selection changes, so `rowSelection` is a prop that the body never+// reads: it is there to make the memo render the rows again.function DataTableBodyInner<TData, TValue>({rows,columns,@@ -363,6 +366,7 @@ function DataTableBodyInner<TData, TValue>({empty,}: {rows: Row<TData>[]+ rowSelection: RowSelectionStatecolumns: ColumnDef<TData, TValue>[]filler: booleanonRowClick?: (row: TData) => void@@ -528,6 +532,7 @@ function DataTable<TData, TValue>({</TableHeader><DataTableBodyrows={table.getRowModel().rows}+ rowSelection={table.getState().rowSelection}columns={columns}filler={hasFiller}onRowClick={onRowClick}