Skip to content

Modern Docker Management, Designed for Everyone

refactor: use proper tanstack-table v9 logic

Kyle Mendell5c3c7b703564
diff --git a/frontend/package.json b/frontend/package.json
index fdc3c8bd7..2b6989a19 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -36,8 +36,8 @@
"@simplewebauthn/browser": "^13.3.0",
"@sveltejs/kit": "^3.0.0-next.13",
"@tanstack/svelte-query": "^6.1.38",
- "@tanstack/svelte-table": "^9.0.0-beta.78",
- "@tanstack/table-core": "9.0.0-beta.78",
+ "@tanstack/svelte-table": "^9.1.0",
+ "@tanstack/table-core": "9.1.0",
"@tanstack/virtual-core": "^3.17.7",
"@uiw/codemirror-themes": "^4.25.11",
"@xterm/addon-fit": "^0.11.0",
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelte b/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelte
index 19f89ce44..10286b7c8 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-desktop-view.svelte
@@ -1,5 +1,5 @@
<script lang="ts" generics="TData extends Record<string, any> & { id: string }">
- import type { ArcaneCell, ArcaneHeader, ArcaneRow, ArcaneSvelteTable } from './table-features';
+ import type { ArcaneCell, ArcaneFeatures, ArcaneRow, ArcaneSvelteTable } from './table-features';
import { FlexRender as FlexRenderBase } from '@tanstack/svelte-table';
import { createVirtualizer } from './virtualizer.svelte';
import Skeleton from '#lib/components/ui/skeleton/skeleton.svelte';
@@ -69,9 +69,9 @@
const hasExpand = $derived(!!expandedRowContent);
// FlexRender's generics can't be inferred from its union-shaped props, so unaided it
- // resolves to the broad `Cell<TableFeatures, …>` (which includes feature APIs our cells
- // don't carry). Pin it to the Arcane feature set instead.
- const FlexRender = FlexRenderBase as unknown as Component<{ cell: ArcaneCell<TData> } | { header: ArcaneHeader<TData> }>;
+ // resolves to the broad `Cell<TableFeatures, RowData, …>` and fails invariance against our
+ // concrete cells. Pin them with an instantiation expression — no cast involved.
+ const FlexRender = FlexRenderBase<ArcaneFeatures, TData, unknown>;
// Get column width class from meta
function getWidthClass(width?: ColumnWidth): string {
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte b/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte
index 058fd48a4..aef35510d 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-filter.svelte
@@ -10,7 +10,8 @@
import { CheckIcon, FilterIcon } from '#lib/icons';
// Structural shape of the faceted-filter column controls — see the note in
- // arcane-table-header.svelte for why we avoid v9's invariant `Column` generic here.
+ // arcane-table-header.svelte for why v9's invariant `Column` generic (even with `any`
+ // TData) can't be used here.
type FilterableColumn = {
getFilterValue: () => unknown;
setFilterValue: (value: unknown) => void;
@@ -33,7 +34,7 @@
showCheckboxes?: boolean;
} = $props();
- const selectedValues = $derived(new SvelteSet(column?.getFilterValue() as any[]));
+ const selectedValues = $derived(new SvelteSet((column?.getFilterValue() ?? []) as (string | boolean)[]));
</script>
<Popover.Root>
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-header.svelte b/frontend/src/lib/components/arcane-table/arcane-table-header.svelte
index 0942e3302..8eb3554f0 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-header.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-header.svelte
@@ -9,8 +9,9 @@
type DivAttributes = SvelteHTMLElements['div'];
// Structural shape of the column controls this header drives. v9's `Column<TFeatures, TData>`
- // is invariant in TData and can't be threaded cleanly through `renderComponent`, so we depend
- // only on the methods used here — the real column satisfies this with no generic and no `any`.
+ // is declared `in out TData` (invariant), so even `ArcaneColumn<any>` rejects the deferred
+ // `TData` at the renderComponent call site (re-verified at 9.1.0 stable, 2026-08). Depending
+ // only on the methods used here keeps the prop generic-free with no `any`.
type SortableHeaderColumn = {
getCanSort: () => boolean;
getIsSorted: () => false | 'asc' | 'desc';
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte b/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
index 897b223f7..f8ef7a4a5 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-toolbar.svelte
@@ -16,7 +16,7 @@
import type { Snippet } from 'svelte';
import { cn } from '#lib/utils';
import { ResetIcon, SearchIcon, FilterIcon } from '#lib/icons';
- import type { BulkAction, FilterOption } from './arcane-table.types.svelte';
+ import type { BulkAction } from './arcane-table.types.svelte';
import * as Popover from '#lib/components/ui/popover/index.js';
let {
@@ -73,9 +73,7 @@
table.getAllColumns().some((col) => col.id === 'serviceCount') ? table.getColumn('serviceCount') : undefined
);
const typeColumn = $derived(table.getAllColumns().some((col) => col.id === 'type') ? table.getColumn('type') : undefined);
- const typeColumnFilterOptions = $derived(
- (typeColumn?.columnDef.meta as { filterOptions?: FilterOption[] } | undefined)?.filterOptions ?? []
- );
+ const typeColumnFilterOptions = $derived(typeColumn?.columnDef.meta?.filterOptions ?? []);
const debouncedSetGlobal = debounced((v: string) => table.setGlobalFilter(v), 300);
const imageNameFilterOptionsFormatted = $derived(imageNameFilterOptions.map((name) => ({ label: name, value: name })));
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.svelte b/frontend/src/lib/components/arcane-table/arcane-table.svelte
index be3588375..6093c0ab4 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table.svelte
@@ -1,5 +1,5 @@
<script lang="ts" generics="TData extends Record<string, any> & { id: string }">
- import { createTable, renderComponent, renderSnippet } from '@tanstack/svelte-table';
+ import { createTable, createTableState, renderComponent, renderSnippet } from '@tanstack/svelte-table';
import type { ColumnFiltersState, RowSelectionState, SortingState, ColumnVisibilityState } from '@tanstack/table-core';
import { arcaneTableFeatures, type ArcaneColumnDef, type ArcaneRow, type ArcaneTable } from './table-features';
import DataTableToolbar from './arcane-table-toolbar.svelte';
@@ -115,10 +115,13 @@
// Default page size constant
const DEFAULT_LIMIT = 20;
- let rowSelection = $state<RowSelectionState>({});
- let columnFilters = $state<ColumnFiltersState>([]);
- let sorting = $state<SortingState>([]);
- let globalFilter = $state<string>(requestOptions?.search ?? '');
+ // Table state slices owned outside the table; createTableState applies both value and
+ // functional updater forms from the on[State]Change callbacks. columnVisibility is the
+ // exception — parents two-way bind it, so it stays a $bindable prop.
+ const [rowSelection, setRowSelection] = createTableState<RowSelectionState>({});
+ const [columnFilters, setColumnFilters] = createTableState<ColumnFiltersState>([]);
+ const [sorting, setSorting] = createTableState<SortingState>([]);
+ const [globalFilter, setGlobalFilter] = createTableState<string>(requestOptions?.search ?? '');
const enablePersist = $derived(!!persistKey);
const getEffectiveLimit = () => requestOptions?.pagination?.limit ?? items?.pagination?.itemsPerPage ?? DEFAULT_LIMIT;
@@ -148,8 +151,6 @@
expandedRows = next;
}
- const passAllGlobal: (row: unknown, columnId: string, filterValue: unknown) => boolean = () => true;
-
// Client-sorted columns (spec.clientSort): the server can't order these values,
// so header clicks reorder the current page locally via the column accessor.
const clientSortAccessors = $derived.by(() => {
@@ -166,7 +167,7 @@
const sortedData = $derived.by(() => {
const data = items.data ?? [];
- const first = sorting[0];
+ const first = sorting()[0];
const accessor = first ? clientSortAccessors.get(String(first.id)) : undefined;
if (!first || !accessor) return data;
const direction = first.desc ? -1 : 1;
@@ -209,7 +210,7 @@
let shouldRefresh = false;
const { restoredFilters, filtersMap } = snapshot;
if (restoredFilters.length) {
- columnFilters = restoredFilters;
+ setColumnFilters(restoredFilters);
}
if (Object.keys(filtersMap).length > 0) {
if (!filterMapsEqual(filtersMap, requestOptions?.filters)) {
@@ -233,8 +234,8 @@
const currentSearch = (requestOptions?.search ?? '').trim();
// Incoming requestOptions.search (e.g. from URL param) takes priority over persisted state
const effectiveSearch = currentSearch || persistedSearch;
- if (effectiveSearch !== globalFilter) {
- globalFilter = effectiveSearch;
+ if (effectiveSearch !== globalFilter()) {
+ setGlobalFilter(effectiveSearch);
}
if (effectiveSearch !== currentSearch) {
requestOptions = {
@@ -438,20 +439,12 @@
return `${colIds}:${hasRowActions}:${isSelectionDisabled}`;
}
- let cachedColumnsDef = $state<ArcaneColumnDef<TData>[]>([]);
- let lastColumnsKey = '';
-
- // Use $effect to rebuild columns only when structure changes
- $effect(() => {
- const key = getColumnsKey(columns, !!rowActions, selectionDisabled);
- if (key !== lastColumnsKey) {
- cachedColumnsDef = buildColumns(columns, selectionDisabled);
- lastColumnsKey = key;
- }
+ const columnsKey = $derived(getColumnsKey(columns, !!rowActions, selectionDisabled));
+ const columnsDef = $derived.by(() => {
+ columnsKey; // structural dependency: identity-churned `columns` arrays with an unchanged key don't rebuild defs
+ return untrack(() => buildColumns(columns, selectionDisabled));
});
- const columnsDef = $derived(cachedColumnsDef.length > 0 ? cachedColumnsDef : buildColumns(columns, selectionDisabled));
-
const table = createTable({
features: arcaneTableFeatures,
// Manual / server-side mode: no client row models are registered, so sorting and
@@ -468,36 +461,33 @@
},
state: {
get sorting() {
- return sorting;
+ return sorting();
},
get columnVisibility() {
return columnVisibility;
},
get rowSelection() {
- return rowSelection;
+ return rowSelection();
},
get columnFilters() {
- return columnFilters;
+ return columnFilters();
},
get globalFilter() {
- return globalFilter;
+ return globalFilter();
}
},
get columns() {
return columnsDef;
},
- globalFilterFn: passAllGlobal,
get enableRowSelection() {
return !selectionDisabled;
},
- onRowSelectionChange: (updater) => {
- rowSelection = typeof updater === 'function' ? updater(rowSelection) : updater;
- },
+ onRowSelectionChange: setRowSelection,
onSortingChange: (updater) => {
- const next = typeof updater === 'function' ? updater(sorting) : updater;
- const wasClientSort = sorting[0] && clientSortAccessors.has(String(sorting[0].id));
- sorting = next;
- const first = next[0];
+ const prev = sorting();
+ const wasClientSort = prev[0] && clientSortAccessors.has(String(prev[0].id));
+ setSorting(updater);
+ const first = sorting()[0];
// Client-sorted columns reorder locally — no server round-trip, no persisted sort.
if (first && clientSortAccessors.has(String(first.id))) return;
if (!first && wasClientSort) return;
@@ -532,13 +522,13 @@
onRefresh(requestOptions);
},
onColumnFiltersChange: (updater) => {
- columnFilters = typeof updater === 'function' ? updater(columnFilters) : updater;
+ setColumnFilters(updater);
if (enablePersist && prefs) {
- prefs.current = { ...prefs.current, f: encodeFilters(columnFilters) };
+ prefs.current = { ...prefs.current, f: encodeFilters(columnFilters()) };
}
requestOptions = {
...requestOptions,
- filters: toFilterMap(columnFilters),
+ filters: toFilterMap(columnFilters()),
pagination: {
page: 1,
limit: requestOptions?.pagination?.limit ?? items?.pagination?.itemsPerPage ?? 10
@@ -556,7 +546,7 @@
const activeSort = requestOptions?.sort;
if (activeSort && nextVisibility[activeSort.column] === false && hiddenSortFallback) {
- sorting = [{ id: hiddenSortFallback.column, desc: hiddenSortFallback.direction === 'desc' }];
+ setSorting([{ id: hiddenSortFallback.column, desc: hiddenSortFallback.direction === 'desc' }]);
requestOptions = {
...requestOptions,
sort: hiddenSortFallback,
@@ -571,17 +561,18 @@
onRefresh(requestOptions);
}
},
- onGlobalFilterChange: (value) => {
- globalFilter = (value ?? '') as string;
+ onGlobalFilterChange: (updater) => {
+ setGlobalFilter(updater);
+ if (typeof globalFilter() !== 'string') setGlobalFilter('');
const limit = requestOptions?.pagination?.limit ?? items?.pagination?.itemsPerPage ?? 10;
requestOptions = {
...requestOptions,
- search: globalFilter,
+ search: globalFilter(),
pagination: { page: 1, limit }
};
// Persist global filter
if (enablePersist && prefs) {
- prefs.current = { ...prefs.current, g: globalFilter };
+ prefs.current = { ...prefs.current, g: globalFilter() };
}
onRefresh(requestOptions);
}
@@ -673,12 +664,12 @@
$effect(() => {
const s = requestOptions?.sort;
- const currentSort = untrack(() => sorting[0]);
+ const currentSort = untrack(() => sorting()[0]);
if (!s) {
if (currentSort) {
untrack(() => {
- sorting = [];
+ setSorting([]);
});
}
return;
@@ -687,7 +678,7 @@
const desc = s.direction === 'desc';
if (!currentSort || currentSort.id !== s.column || currentSort.desc !== desc) {
untrack(() => {
- sorting = [{ id: s.column, desc }];
+ setSorting([{ id: s.column, desc }]);
});
}
});
@@ -698,10 +689,10 @@
// the forward onColumnFiltersChange path.
$effect(() => {
const incoming = requestOptions?.filters;
- const currentMap = untrack(() => toFilterMap(columnFilters));
+ const currentMap = untrack(() => toFilterMap(columnFilters()));
if (filterMapsEqual(incoming, currentMap)) return;
untrack(() => {
- columnFilters = fromFilterMap(incoming);
+ setColumnFilters(fromFilterMap(incoming));
});
});
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts b/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts
index ccad4b930..b302e8533 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts
+++ b/frontend/src/lib/components/arcane-table/arcane-table.types.svelte.ts
@@ -1,4 +1,4 @@
-import type { CellData, ColumnFiltersState, ColumnVisibilityState, RowData, TableFeatures } from '@tanstack/table-core';
+import type { ColumnFiltersState, ColumnVisibilityState, RowData } from '@tanstack/table-core';
import type { ArcaneColumn, ArcaneFilterFn, ArcaneRow, ArcaneSvelteTable } from './table-features';
import type { Snippet } from 'svelte';
import type { Component } from 'svelte';
@@ -24,20 +24,6 @@ export type SortState = { column: string; direction: SortDirection };
export type ColumnWidth = 'auto' | 'min' | 'max' | number;
export type ColumnAlign = 'left' | 'center' | 'right';
-// Arcane stows presentation hints on each column's `meta`. Augmenting v9's `ColumnMeta`
-// (which now threads TFeatures/TData/TValue) types these instead of the inline
-// `meta as { … }` casts the desktop view / toolbar / view-options used to read them back.
-// The generic signature must mirror table-core's declaration for declaration merging.
-declare module '@tanstack/table-core' {
- interface ColumnMeta<TFeatures extends TableFeatures, TData extends RowData, TValue extends CellData = CellData> {
- title?: string;
- filterOptions?: FilterOption[];
- width?: ColumnWidth;
- align?: ColumnAlign;
- truncate?: boolean;
- }
-}
-
export type ColumnSpec<T extends RowData> = {
accessorKey?: keyof T & string;
accessorFn?: (row: T) => any;
@@ -93,7 +79,7 @@ export function applyHiddenPatch(target: ColumnVisibilityState, hidden?: string[
}
export function encodeFilters(filters: ColumnFiltersState): [string, unknown][] {
- return (filters ?? []).map((f) => [f.id, (f as any).value] as [string, unknown]);
+ return (filters ?? []).map((f) => [f.id, f.value] as [string, unknown]);
}
export function decodeFilters(pairs?: [string, unknown][]): ColumnFiltersState {
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.utils.ts b/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
index bcf0d0696..df2e59029 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
+++ b/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
@@ -1,5 +1,5 @@
import type { ColumnFiltersState } from '@tanstack/table-core';
-import type { FilterMap } from '#lib/types/shared';
+import type { FilterMap, FilterValue } from '#lib/types/shared';
import type { CompactTablePrefs } from './arcane-table.types.svelte';
import { decodeFilters, decodeSort } from './arcane-table.types.svelte';
@@ -18,17 +18,19 @@ export function toFilterMap(filters: ColumnFiltersState): FilterMap {
const out: FilterMap = {};
for (const f of filters ?? []) {
const id = f.id;
- let value: unknown = (f as any).value;
+ let value: unknown = f.value;
if (value instanceof Set) {
value = Array.from(value);
}
+ // Filter values originate from facet options / inputs, so they always fit
+ // FilterValue; the cast bridges tanstack's `unknown` at this one boundary.
if (Array.isArray(value)) {
if (value.length === 0) continue;
- out[id] = value as any[];
+ out[id] = value as FilterValue;
} else if (value !== undefined && value !== null && String(value).trim() !== '') {
- out[id] = value as any;
+ out[id] = value as FilterValue;
}
}
return out;
diff --git a/frontend/src/lib/components/arcane-table/table-features.ts b/frontend/src/lib/components/arcane-table/table-features.ts
index 39a24788b..4526b8acf 100644
--- a/frontend/src/lib/components/arcane-table/table-features.ts
+++ b/frontend/src/lib/components/arcane-table/table-features.ts
@@ -7,7 +7,23 @@ import {
tableFeatures,
type SvelteTable
} from '@tanstack/svelte-table';
+import { metaHelper } from '@tanstack/table-core';
import type { Cell, Column, ColumnDef, FilterFn, Header, Row, RowData, Table } from '@tanstack/table-core';
+// Type-only cycle with arcane-table.types.svelte.ts (which imports only types from here) — erased at emit.
+import type { ColumnAlign, ColumnWidth, FilterOption } from './arcane-table.types.svelte';
+
+/**
+ * Presentation hints Arcane stows on each column's `meta`. Declared through the v9
+ * `columnMeta` type-only slot on `tableFeatures()` below (instead of globally augmenting
+ * table-core's `ColumnMeta`), so the typing stays scoped to the Arcane feature set.
+ */
+export interface ArcaneColumnMeta {
+ title?: string;
+ filterOptions?: FilterOption[];
+ width?: ColumnWidth;
+ align?: ColumnAlign;
+ truncate?: boolean;
+}
/**
* The single, app-wide TanStack Table v9 feature set shared by every Arcane table.
@@ -27,7 +43,8 @@ export const arcaneTableFeatures = tableFeatures({
columnVisibilityFeature,
rowSortingFeature,
columnFilteringFeature,
- globalFilteringFeature
+ globalFilteringFeature,
+ columnMeta: metaHelper<ArcaneColumnMeta>()
});
/**
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index da2e79ec0..e371f73a9 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -132,11 +132,11 @@ importers:
specifier: ^6.1.38
version: 6.1.38([email protected])
'@tanstack/svelte-table':
- specifier: ^9.0.0-beta.78
- version: 9.0.0-beta.78([email protected])
+ specifier: ^9.1.0
+ version: 9.1.0([email protected])
'@tanstack/table-core':
- specifier: 9.0.0-beta.78
- version: 9.0.0-beta.78
+ specifier: 9.1.0
+ version: 9.1.0
'@tanstack/virtual-core':
specifier: ^3.17.7
version: 3.17.7
@@ -1232,14 +1232,14 @@ packages:
peerDependencies:
svelte: ^5.0.0
- '@tanstack/[email protected]':
- resolution: {integrity: sha512-TmanI8pzBL3HOdjWSL1e76viE483+foDLltprufIarceuThrHf2UR/5e/6MiRcyQPB1XY/SBr9SgjEs0fZwzLw==}
+ '@tanstack/[email protected]':
+ resolution: {integrity: sha512-uWwvEjeru+3jLP59sfSknk1569ePH2EYoZALGxnDbScvgqKXveYoYB/Tc4CfwPKQhyg0koxvVg8ixY9fPMAW9g==}
engines: {node: '>=20'}
peerDependencies:
svelte: ^5.0.0
- '@tanstack/[email protected]':
- resolution: {integrity: sha512-PbVO8JCaBKD6/hipdpFaq6t7PWA/VbioJClSR6fWFmPbQdT0C3pJHdne1o24XBY62BqlHc8h/twY6nRsLj2DIw==}
+ '@tanstack/[email protected]':
+ resolution: {integrity: sha512-tvnnqdWlvF/l6P65yS4ca4keW2VCC3e+OTT8/pUM7ZF5OQBJ7zTVy67T0lLpWBpkELrZN8sFJxY5DHF05fLUDQ==}
engines: {node: '>=20'}
'@tanstack/[email protected]':
@@ -3677,13 +3677,13 @@ snapshots:
'@tanstack/store': 0.11.0
svelte: 5.56.8
dependencies:
'@tanstack/svelte-store': 0.12.0([email protected])
- '@tanstack/table-core': 9.0.0-beta.78
+ '@tanstack/table-core': 9.1.0
svelte: 5.56.8
- '@tanstack/[email protected]':
+ '@tanstack/[email protected]':
dependencies:
'@tanstack/store': 0.11.0
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index bfa6f4c24..1693ae4fe 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -39,5 +39,5 @@ allowBuilds:
sharp: true
minimumReleaseAgeExclude:
- - '@tanstack/[email protected]'
- - '@tanstack/[email protected]'
+ - '@tanstack/[email protected] || 9.1.0'
+ - '@tanstack/[email protected] || 9.1.0'