From be79b7159c5da425c7820b3a26320ea986037048 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Sat, 25 Apr 2026 01:05:11 +0100 Subject: [PATCH] feat(base): warm row count query on base load, gated on user hydrate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mounts useBaseRowsCountQuery alongside the rows query so the count is fetched eagerly and the cache is warm by the time the toolbar consumes it. Gating on `currentUser` (not just `base`) ensures the persisted view-draft has hydrated from localStorage before the first count fires — otherwise a post-refresh count races ahead of the user's saved filter and ships without it. --- .../src/features/base/components/base-table.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/client/src/features/base/components/base-table.tsx b/apps/client/src/features/base/components/base-table.tsx index 16fab46df..cfd81beb5 100644 --- a/apps/client/src/features/base/components/base-table.tsx +++ b/apps/client/src/features/base/components/base-table.tsx @@ -14,6 +14,7 @@ import { } from "@/features/base/types/base.types"; import { useBaseRowsQuery, + useBaseRowsCountQuery, flattenRows, } from "@/features/base/queries/base-row-query"; import { useUpdateRowMutation } from "@/features/base/queries/base-row-query"; @@ -120,6 +121,18 @@ export function BaseTable({ baseId }: BaseTableProps) { const { data: rowsData, isLoading: rowsLoading, fetchNextPage, hasNextPage, isFetchingNextPage } = useBaseRowsQuery(base ? baseId : undefined, activeFilter, activeSorts); + // Fire the count request alongside the rows query. Not rendered yet — + // this mounts the query so its cache is warm for when the toolbar + // consumes it. Gate on `currentUser` too so `useViewDraft` has had a + // chance to hydrate the persisted draft from localStorage; otherwise + // the first post-refresh count would race ahead of the user's saved + // filter and fire with baseline-only (or nothing). + const canFetchCount = !!base && !!currentUser; + useBaseRowsCountQuery( + canFetchCount ? baseId : undefined, + activeFilter, + ); + const updateRowMutation = useUpdateRowMutation(); const createRowMutation = useCreateRowMutation(); const reorderRowMutation = useReorderRowMutation();