feat(base): warm row count query on base load, gated on user hydrate

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.
This commit is contained in:
Philipinho
2026-04-25 01:05:11 +01:00
parent 18222d1142
commit be79b7159c
@@ -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();