From a6e9e66bbd2041f29c2c1284838a890c1af621dc Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sat, 18 Apr 2026 22:55:15 +0100 Subject: [PATCH] fix(base): don't override server sort with client-side position sort --- .../src/features/base/components/base-table.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/client/src/features/base/components/base-table.tsx b/apps/client/src/features/base/components/base-table.tsx index 9704dc4e..b6c39168 100644 --- a/apps/client/src/features/base/components/base-table.tsx +++ b/apps/client/src/features/base/components/base-table.tsx @@ -65,8 +65,20 @@ export function BaseTable({ baseId }: BaseTableProps) { const rows = useMemo(() => { const flat = flattenRows(rowsData); - return flat.sort((a, b) => (a.position < b.position ? -1 : a.position > b.position ? 1 : 0)); - }, [rowsData]); + // When a sort is active, the server returns rows in the requested + // sort order via keyset pagination. Re-sorting by `position` on the + // client would override that with fractional-index order — visibly + // breaking the sort as more pages load. Only apply the position + // sort when no view sort is active (where it keeps + // optimistically-created and ws-pushed rows in place without a + // refetch). + if (activeSorts && activeSorts.length > 0) { + return flat; + } + return flat.sort((a, b) => + a.position < b.position ? -1 : a.position > b.position ? 1 : 0, + ); + }, [rowsData, activeSorts]); const { table, persistViewConfig } = useBaseTable(base, rows, activeView);