Skip to content

Modern Docker Management, Designed for Everyone

perf(frontend): improve table scrolling while preserving glass effects

Kyle Mendellca9917fc5cbd
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 17fd78517..5218b16d9 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
@@ -8,7 +8,6 @@
import { m } from '#lib/paraglide/messages';
import { cn } from '#lib/utils';
import {
- getTableRowsForItems,
shouldIgnoreTableRowClick,
type ColumnWidth,
type ColumnAlign,
@@ -17,15 +16,18 @@
} from './arcane-table.types.svelte';
import TableCheckbox from './arcane-table-checkbox.svelte';
import TableEmpty from './table-empty.svelte';
- import type { Component, Snippet } from 'svelte';
+ import { untrack, type Component, type Snippet } from 'svelte';
import type { Attachment } from 'svelte/attachments';
import { slide } from 'svelte/transition';
+ import { getTableRowsForItems } from './arcane-table.utils';
void slide;
let {
table,
- selectedIds,
+ rowIndex,
+ selectedIdSet,
+ initialScrollTop = 0,
columnsCount,
groupedRows = null,
groupIcon,
@@ -44,7 +46,9 @@
wrapText = false
}: {
table: ArcaneSvelteTable<TData>;
- selectedIds: string[];
+ rowIndex: ReadonlyMap<string, { row: ArcaneRow<TData>; index: number }>;
+ selectedIdSet: ReadonlySet<string>;
+ initialScrollTop?: number;
columnsCount: number;
groupedRows?: GroupedData<TData>[] | null;
groupIcon?: (groupName: string) => Component;
@@ -78,7 +82,6 @@
if (!width || width === 'auto') return '';
if (width === 'min') return 'w-0';
if (width === 'max') return 'w-full';
- if (typeof width === 'number') return `w-[${width}px]`;
return '';
}
@@ -101,7 +104,7 @@
return;
}
if (selectionDisabled) return;
- const isSelected = (selectedIds ?? []).includes(rowId);
+ const isSelected = selectedIdSet.has(rowId);
onToggleRowSelection?.(rowId, !isSelected);
}
@@ -122,30 +125,71 @@
// Get rows for a specific group from the table model
const isGrouped = $derived(groupedRows !== null && groupedRows.length > 0);
- // --- Row virtualization ---------------------------------------------------------------------
- // Only the flat (non-grouped, non-expandable) path is virtualized, and only past a threshold —
- // the case that matters is the "All" page size (TABLE_PAGE_SIZE_ALL), where the server returns
- // the full unpaginated set. Normal paginated pages (<= 100 rows) render plainly. Grouped and
- // expandable layouts keep their existing, proven rendering.
+ // Keep small pages and variable-layout views on the regular table path.
const VIRTUALIZE_THRESHOLD = 100;
- // Rows are strictly single-line (Table.Cell is `whitespace-nowrap`) so they all share one height.
- // We virtualize with a fixed row height instead of measuring every row: dynamic per-row measurement
- // made the "All" view flicker — with an estimate that differed from the real height, each row
- // re-measured as it scrolled in and nudged the rows already on screen. Calibrate once from the first
- // rendered row, after which every offset is exact and stable.
const ROW_ESTIMATE_PX = 44;
let measuredRowHeight = $state<number | null>(null);
+ let tableElement = $state<HTMLTableElement | null>(null);
+ let bodyElement = $state<HTMLTableSectionElement | null>(null);
+ let scrollMargin = $state(0);
const flatRows = $derived(table.getRowModel().rows);
const shouldVirtualize = $derived(
!isGrouped && !hasExpand && !wrapText && !!scrollElement && flatRows.length > VIRTUALIZE_THRESHOLD
);
+ const getItemKey = $derived.by(() => {
+ const rows = flatRows;
+ return (index: number) => rows[index]?.id ?? index;
+ });
- function calibrateRowHeight(node: HTMLTableRowElement) {
- if (measuredRowHeight !== null) return;
- const h = node.getBoundingClientRect().height;
- if (h > 0) measuredRowHeight = h;
+ function measureRow(node: HTMLTableRowElement) {
+ untrack(() => {
+ if (measuredRowHeight === null) {
+ const height = node.getBoundingClientRect().height;
+ if (height > 0) measuredRowHeight = height;
+ }
+ rowVirtualizer.measureElement(node);
+ });
+ return () => queueMicrotask(() => rowVirtualizer.measureElement(null));
}
+ $effect(() => {
+ const container = scrollElement;
+ const tableNode = tableElement;
+ const body = bodyElement;
+ if (!shouldVirtualize || !container || !tableNode || !body) return;
+
+ table.getVisibleLeafColumns();
+ let width = 0;
+ const remeasure = () => {
+ const row = body.querySelector<HTMLTableRowElement>('tr[data-index]');
+ const height = row?.getBoundingClientRect().height;
+ if (height) measuredRowHeight = height;
+ rowVirtualizer.measure();
+ };
+ const updateLayout = () => {
+ const nextWidth = tableNode.getBoundingClientRect().width;
+ scrollMargin =
+ body.getBoundingClientRect().top - container.getBoundingClientRect().top + container.scrollTop - container.clientTop;
+ if (nextWidth !== width) {
+ width = nextWidth;
+ remeasure();
+ }
+ };
+ const fontsChanged = () => {
+ remeasure();
+ updateLayout();
+ };
+ const observer = new ResizeObserver(updateLayout);
+ observer.observe(tableNode);
+ if (tableNode.tHead) observer.observe(tableNode.tHead);
+ document.fonts.addEventListener('loadingdone', fontsChanged);
+ untrack(updateLayout);
+ return () => {
+ observer.disconnect();
+ document.fonts.removeEventListener('loadingdone', fontsChanged);
+ };
+ });
+
// Row actions are a real pinned column: sticky to the row's right edge with its own reserved
// width, so the floating button never overlaps data columns and survives horizontal scroll.
// The gutter must stay opaque to mask content scrolling beneath it, so it can't bg-inherit the
@@ -173,7 +217,9 @@
getScrollElement: () => scrollElement ?? null,
estimateSize: () => rowSize,
overscan: 10,
- getItemKey: (index) => flatRows[index]?.id ?? index,
+ getItemKey,
+ initialOffset: initialScrollTop,
+ scrollMargin,
enabled: shouldVirtualize
};
});
@@ -194,15 +240,21 @@
{/if}
{/snippet}
-{#snippet dataRow(row: ArcaneRow<TData>, isGroupedRow: boolean, measureRow?: Attachment<HTMLTableRowElement>)}
+{#snippet dataRow(
+ row: ArcaneRow<TData>,
+ isGroupedRow: boolean,
+ rowMeasurement?: Attachment<HTMLTableRowElement>,
+ virtualIndex?: number
+)}
{@const rowId = row.original.id}
{@const isExpanded = expandedRows?.has(rowId) ?? false}
<Table.Row
- {@attach measureRow}
- data-state={(selectedIds ?? []).includes(rowId) && 'selected'}
+ {@attach rowMeasurement}
+ data-index={virtualIndex}
+ data-state={selectedIdSet.has(rowId) && 'selected'}
data-expanded={isExpanded ? true : undefined}
onclick={(event) => handleRowClick(event, rowId)}
- class={cn(hasExpand && 'cursor-pointer', isExpanded && 'bg-primary/15')}
+ class={cn('isolate', hasExpand && 'cursor-pointer', isExpanded && 'bg-primary/15')}
>
{#if hasExpand}
<Table.Cell class="w-8 px-2" data-row-select-ignore>
@@ -221,7 +273,10 @@
{/if}
{#each row.getVisibleCells() as cell, cellIndex (cell.id)}
{@const isFirstDataCell = !selectionDisabled ? cellIndex === 1 : cellIndex === 0}
- <Table.Cell class={getCellClasses(cell, isGroupedRow, isFirstDataCell)}>
+ <Table.Cell
+ style={typeof cell.column.columnDef.meta?.width === 'number' ? `width: ${cell.column.columnDef.meta.width}px` : undefined}
+ class={getCellClasses(cell, isGroupedRow, isFirstDataCell)}
+ >
{@render cellContent(cell)}
</Table.Cell>
{/each}
@@ -270,7 +325,7 @@
{#if !unstyled}
<div aria-hidden="true" class="sticky top-0 z-[var(--arcane-z-sticky)] -mb-10 h-10 backdrop-blur-sm"></div>
{/if}
- <Table.Root class={shouldVirtualize ? 'table-fixed' : undefined}>
+ <Table.Root bind:ref={tableElement} class={shouldVirtualize ? 'table-fixed' : undefined}>
<Table.Header>
{#each table.getHeaderGroups() as headerGroup (headerGroup.id)}
<Table.Row>
@@ -280,7 +335,11 @@
{#each headerGroup.headers as header (header.id)}
<Table.Head
colspan={header.colSpan}
+ style={typeof header.column.columnDef.meta?.width === 'number'
+ ? `width: ${header.column.columnDef.meta.width}px`
+ : undefined}
class={cn(
+ getWidthClass(header.column.columnDef.meta?.width),
header.column.id === 'select' && selectCellClasses,
header.column.id === 'actions' && cn(actionsCellClasses, 'z-[var(--arcane-z-page-floating)] bg-background')
)}
@@ -293,11 +352,10 @@
</Table.Row>
{/each}
</Table.Header>
- <Table.Body>
+ <Table.Body bind:ref={bodyElement}>
{#if isGrouped && groupedRows}
{#each groupedRows as group (group.groupName)}
{@const isCollapsed = groupCollapsedState[group.groupName] ?? true}
- {@const groupRows = getTableRowsForItems(table, group.items)}
{@const selectionState = getGroupSelectionState?.(group.items) ?? 'none'}
{@const hasSelection = selectionState !== 'none'}
{@const IconComponent = groupIcon?.(group.groupName)}
@@ -338,6 +396,7 @@
<!-- Group Items (if not collapsed) -->
{#if !isCollapsed}
+ {@const groupRows = getTableRowsForItems(rowIndex, group.items)}
{#each groupRows as row (row.id)}
{@render dataRow(row, true)}
{/each}
@@ -356,15 +415,15 @@
{@const vItems = rowVirtualizer.virtualItems}
{@const first = vItems[0]}
{@const last = vItems[vItems.length - 1]}
- {@const padTop = first ? first.start : 0}
- {@const padBottom = last ? rowVirtualizer.totalSize - last.end : 0}
+ {@const padTop = first ? Math.max(0, first.start - scrollMargin) : 0}
+ {@const padBottom = last ? Math.max(0, rowVirtualizer.totalSize - (last.end - scrollMargin)) : 0}
{#if padTop > 0}
<tr aria-hidden="true"><td colspan={columnsCount} class="border-0 p-0" style="height: {padTop}px"></td></tr>
{/if}
{#each vItems as vItem (vItem.key)}
{@const row = flatRows[vItem.index]}
{#if row}
- {@render dataRow(row, false, calibrateRowHeight)}
+ {@render dataRow(row, false, measureRow, vItem.index)}
{/if}
{/each}
{#if padBottom > 0}
diff --git a/frontend/src/lib/components/arcane-table/arcane-table-mobile-view.svelte b/frontend/src/lib/components/arcane-table/arcane-table-mobile-view.svelte
index 7931d5794..152b03aca 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table-mobile-view.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table-mobile-view.svelte
@@ -6,13 +6,15 @@
import { m } from '#lib/paraglide/messages';
import { cn } from '#lib/utils';
import type { Snippet, Component } from 'svelte';
- import { getTableRowsForItems, shouldIgnoreTableRowClick, type GroupedData } from './arcane-table.types.svelte';
+ import { shouldIgnoreTableRowClick, type GroupedData } from './arcane-table.types.svelte';
import { slide } from 'svelte/transition';
+ import { getTableRowsForItems } from './arcane-table.utils';
void slide;
let {
table,
+ rowIndex,
mobileCard,
mobileFieldVisibility,
groupedRows = null,
@@ -24,6 +26,7 @@
loading = false
}: {
table: ArcaneSvelteTable<TData>;
+ rowIndex: ReadonlyMap<string, { row: ArcaneRow<TData>; index: number }>;
mobileCard: Snippet<[{ row: ArcaneRow<TData>; item: TData; mobileFieldVisibility: Record<string, boolean> }]>;
mobileFieldVisibility: Record<string, boolean>;
groupedRows?: GroupedData<TData>[] | null;
@@ -86,7 +89,7 @@
{#if isGrouped && groupedRows}
<div class="space-y-4 py-2">
{#each groupedRows as group (group.groupName)}
- {@const groupRows = getTableRowsForItems(table, group.items)}
+ {@const groupRows = getTableRowsForItems(rowIndex, group.items)}
{@const IconComponent = groupIcon?.(group.groupName)}
<DropdownCard
diff --git a/frontend/src/lib/components/arcane-table/arcane-table.svelte b/frontend/src/lib/components/arcane-table/arcane-table.svelte
index 6e46a7ec6..0a3029e7a 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.svelte
+++ b/frontend/src/lib/components/arcane-table/arcane-table.svelte
@@ -4,6 +4,7 @@
import { arcaneTableFeatures, type ArcaneColumnDef, type ArcaneRow, type ArcaneTable } from './table-features';
import DataTableToolbar from './arcane-table-toolbar.svelte';
import { onMount, untrack } from 'svelte';
+ import { IsMobile } from '#lib/hooks/is-mobile.svelte';
import type { Paginated, SearchPaginationSortRequest } from '#lib/types/shared';
import type { Snippet } from 'svelte';
import type { ColumnSpec } from './arcane-table.types.svelte';
@@ -140,6 +141,26 @@
// The desktop scroll container, bound below and handed to the desktop view so it can virtualize
// long flat lists. The unstyled/styled branches are mutually exclusive, so one ref suffices.
let desktopScrollEl = $state<HTMLElement>();
+ const isMobile = new IsMobile();
+ const scrollPositions = { desktop: { top: 0, left: 0 }, mobile: { top: 0, left: 0 } };
+ const selectedIdSet = $derived(new Set(selectedIds ?? []));
+
+ function restoreScroll(node: HTMLElement, view: keyof typeof scrollPositions) {
+ const position = scrollPositions[view];
+ const frame = requestAnimationFrame(() => {
+ node.scrollTop = position.top;
+ node.scrollLeft = position.left;
+ node.addEventListener('scroll', savePosition, { passive: true });
+ });
+ function savePosition() {
+ position.top = node.scrollTop;
+ position.left = node.scrollLeft;
+ }
+ return () => {
+ cancelAnimationFrame(frame);
+ node.removeEventListener('scroll', savePosition);
+ };
+ }
function toggleRowExpanded(rowId: string) {
const next = new Set(expandedRows);
@@ -611,6 +632,8 @@
}))
);
+ const rowIndex = $derived.by(() => new Map(table.getRowModel().rows.map((row, index) => [row.original.id, { row, index }])));
+
// Compute grouped rows when groupBy is provided
const effectiveGroupedRows = $derived.by((): GroupedData<TData>[] | null => {
if (groupedRows) return groupedRows;
@@ -634,8 +657,7 @@
// Get selection state for a group
function getGroupSelectionState(groupItems: TData[]): GroupSelectionState {
const groupIds = groupItems.map((item) => item.id);
- const selectedSet = new Set(selectedIds ?? []);
- const selectedCount = groupIds.filter((id) => selectedSet.has(id)).length;
+ const selectedCount = groupIds.filter((id) => selectedIdSet.has(id)).length;
if (selectedCount === 0) return 'none';
if (selectedCount === groupIds.length) return 'all';
@@ -749,6 +771,7 @@
{#snippet MobileViewSnippet()}
<ArcaneTableMobileView
+ {rowIndex}
{table}
{mobileCard}
{mobileFieldVisibility}
@@ -785,41 +808,49 @@
</div>
{/if}
- <div
- bind:this={desktopScrollEl}
- class="[isolation:isolate] hidden h-full min-h-0 flex-1 overflow-auto bg-background md:block"
- >
- <ArcaneTableDesktopView
- {table}
- {selectedIds}
- columnsCount={effectiveColumnsCount}
- groupedRows={effectiveGroupedRows}
- {groupIcon}
- {groupCollapsedState}
- {selectionDisabled}
- onGroupToggle={handleGroupToggle}
- {getGroupSelectionState}
- {onToggleGroupSelection}
- onToggleRowSelection={(id, selected) => onToggleRow(selected, id)}
- {unstyled}
- {expandedRowContent}
- {expandedRows}
- onToggleRowExpanded={toggleRowExpanded}
- scrollElement={desktopScrollEl}
- {loading}
- {wrapText}
- />
- </div>
-
- <div class="[isolation:isolate] block flex-1 overflow-auto bg-background/80 md:hidden">
- {#if unstyled}
- <div class="divide-y divide-border/40">
+ {#if !isMobile.current}
+ <div
+ {@attach (node) => restoreScroll(node, 'desktop')}
+ bind:this={desktopScrollEl}
+ class="[isolation:isolate] h-full min-h-0 flex-1 overflow-auto bg-background"
+ >
+ <ArcaneTableDesktopView
+ {rowIndex}
+ {table}
+ {selectedIdSet}
+ initialScrollTop={scrollPositions.desktop.top}
+ columnsCount={effectiveColumnsCount}
+ groupedRows={effectiveGroupedRows}
+ {groupIcon}
+ {groupCollapsedState}
+ {selectionDisabled}
+ onGroupToggle={handleGroupToggle}
+ {getGroupSelectionState}
+ {onToggleGroupSelection}
+ onToggleRowSelection={(id, selected) => onToggleRow(selected, id)}
+ {unstyled}
+ {expandedRowContent}
+ {expandedRows}
+ onToggleRowExpanded={toggleRowExpanded}
+ scrollElement={desktopScrollEl}
+ {loading}
+ {wrapText}
+ />
+ </div>
+ {:else}
+ <div
+ {@attach (node) => restoreScroll(node, 'mobile')}
+ class="[isolation:isolate] block flex-1 overflow-auto bg-background/80"
+ >
+ {#if unstyled}
+ <div class="divide-y divide-border/40">
+ {@render MobileViewSnippet()}
+ </div>
+ {:else}
{@render MobileViewSnippet()}
- </div>
- {:else}
- {@render MobileViewSnippet()}
- {/if}
- </div>
+ {/if}
+ </div>
+ {/if}
{#if !withoutPagination}
<div class="shrink-0 border-t border-border/50 px-4 py-3">
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 1ba891a9d..59f4a17e6 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,5 +1,5 @@
import type { ColumnFiltersState, ColumnVisibilityState, RowData } from '@tanstack/table-core';
-import type { ArcaneColumn, ArcaneFilterFn, ArcaneRow, ArcaneSvelteTable } from './table-features';
+import type { ArcaneColumn, ArcaneFilterFn, ArcaneRow } from './table-features';
import type { Snippet } from 'svelte';
import type { Component } from 'svelte';
@@ -170,11 +170,3 @@ export function shouldIgnoreTableRowClick(event: MouseEvent): boolean {
const target = event.target as HTMLElement | null;
return !!target?.closest('a, button, input, [role="checkbox"], [data-slot="checkbox"], [data-row-select-ignore]');
}
-
-export function getTableRowsForItems<T extends RowData & { id?: string }>(
- table: ArcaneSvelteTable<T>,
- groupItems: Array<{ id: string }>
-) {
- const groupIds = new Set(groupItems.map((item) => item.id));
- return table.getRowModel().rows.filter((row) => groupIds.has(row.original.id ?? ''));
-}
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 df2e59029..2ddc91a46 100644
--- a/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
+++ b/frontend/src/lib/components/arcane-table/arcane-table.utils.ts
@@ -1,3 +1,5 @@
+import type { ArcaneRow } from './table-features';
+import type { RowData } from '@tanstack/table-core';
import type { ColumnFiltersState } from '@tanstack/table-core';
import type { FilterMap, FilterValue } from '#lib/types/shared';
import type { CompactTablePrefs } from './arcane-table.types.svelte';
@@ -99,3 +101,17 @@ export function extractPersistedPreferences(
customSettings: prefs.c
};
}
+
+export function getTableRowsForItems<T extends RowData>(
+ rowIndex: ReadonlyMap<string, { row: ArcaneRow<T>; index: number }>,
+ groupItems: Array<{ id: string }>
+): ArcaneRow<T>[] {
+ const ids = new Set(groupItems.map((item) => item.id));
+ return Array.from(ids)
+ .flatMap((id) => {
+ const entry = rowIndex.get(id);
+ return entry ? [entry] : [];
+ })
+ .sort((a, b) => a.index - b.index)
+ .map((entry) => entry.row);
+}
diff --git a/frontend/src/lib/components/ui/virtualizer.svelte.ts b/frontend/src/lib/components/ui/virtualizer.svelte.ts
index 36236e2ec..38a810c48 100644
--- a/frontend/src/lib/components/ui/virtualizer.svelte.ts
+++ b/frontend/src/lib/components/ui/virtualizer.svelte.ts
@@ -72,6 +72,12 @@ export function createVirtualizer<TScroll extends Element, TItem extends Element
return totalSize;
},
/** `use:` action target that measures real row heights for accurate offsets. */
- measureElement: (node: TItem) => instance.measureElement(node)
+ measureElement: (node: TItem | null) => instance.measureElement(node),
+ measure: () => {
+ instance.measure();
+ for (const node of instance.elementsCache.values()) {
+ if (node.isConnected) instance.measureElement(node);
+ }
+ }
};
}
diff --git a/go.work.sum b/go.work.sum
index 9fcf82064..4e5ed3d1c 100644
--- a/go.work.sum
+++ b/go.work.sum
@@ -2640,6 +2640,7 @@ go.getarcane.app/acfs v0.2.0/go.mod h1:sU3t21KctTsQM3OW10+RNB0Z6lR+YfaSr5Nxubq3c
go.getarcane.app/acfs v0.4.1/go.mod h1:sU3t21KctTsQM3OW10+RNB0Z6lR+YfaSr5Nxubq3cpI=
go.getarcane.app/acfs v0.4.2/go.mod h1:58JU/5d9TIawZrRvtND1jBmcDy6DrUP0FLhXklmrRjY=
go.getarcane.app/acfs v0.5.0/go.mod h1:Z+0Gs4LGNjvGMLq+TKv/oGKh29FRbAH6mcVPwY5KhFI=
+go.getarcane.app/acfs v0.5.1/go.mod h1:Z+0Gs4LGNjvGMLq+TKv/oGKh29FRbAH6mcVPwY5KhFI=
go.getarcane.app/builds v0.3.1 h1:jymgkbcJ98o+XM9P0Ympn7m3WowWhG3vbiVwxIhhwns=
go.getarcane.app/builds v0.3.1/go.mod h1:MJXC3VNSspckX6NBu+l7kBaCckuNsXIw4B8WAuxXo94=
go.getarcane.app/builds v0.4.0 h1:i6qHFy1/xuGkKYYXPeNtS7Y/pyNb9ITVr4rnP04a2Kg=