Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix(tables): a list over 1,000 rows runs one exact count per refresh, not two

aashu960742473b6d
diff --git a/.claude/rules/table-infinite-scroll.md b/.claude/rules/table-infinite-scroll.md
index 605627a84e..3fe7be5a33 100644
--- a/.claude/rules/table-infinite-scroll.md
+++ b/.claude/rules/table-infinite-scroll.md
@@ -55,9 +55,10 @@ The header shows the number of matching rows ("2,345 rows"), exact at any size.
1,000 rows. From 1,000 rows up it gives the planner's estimate, because an
exact count (`COUNT(*) OVER ()`) reads every matching row.
2. From 1,000 up, `useExactCount` (`components/Table/useExactCount.ts`) loads
- the list route with `count=exact` in place of `after` (`getCountUrl`),
- after page 1 shows and again after each revalidation. The rows never wait
- for the count.
+ the list route with `count=exact` in place of `after` (`getCountUrl`)
+ after page 1 shows. A revalidation counts again because the router reloads
+ a mounted fetcher's last URL; the hook sends no second request for it.
+ The rows never wait for the count.
3. `getGenericQueryFilters` reads `count=exact` as `exactCount: true` (and no
cursor). `listCount(args)` then asks for `exact`, and
`setGenericQueryFilters` reads one row (`.limit(1)`).
diff --git a/apps/erp/app/components/Table/Table.tsx b/apps/erp/app/components/Table/Table.tsx
index cac5d0e173..7bd4e9d2ea 100644
--- a/apps/erp/app/components/Table/Table.tsx
+++ b/apps/erp/app/components/Table/Table.tsx
@@ -412,7 +412,6 @@ const Table = <T extends object>({
const listKey = infiniteOptions?.listKey;
const { count, isExact: countIsExact } = useExactCount({
count: loaderCount,
- data,
infinite: infiniteOptions
});
diff --git a/apps/erp/app/components/Table/useExactCount.ts b/apps/erp/app/components/Table/useExactCount.ts
index 603c4d7983..4715d95bfb 100644
--- a/apps/erp/app/components/Table/useExactCount.ts
+++ b/apps/erp/app/components/Table/useExactCount.ts
@@ -14,16 +14,15 @@ import type { InfiniteOptions } from "./types";
/**
* The list's row count, exact at any size: from 1,000 rows up it asks for
* `?count=exact` after page 1 shows, keeping the estimate until it arrives.
- * See `.claude/rules/table-infinite-scroll.md` ("The row count").
+ * A revalidation counts again without a new request from here: the router
+ * reloads the fetcher's last URL itself. See
+ * `.claude/rules/table-infinite-scroll.md` ("The row count").
*/
export function useExactCount({
count,
- data,
infinite
}: {
count: number;
- /** The loader's page 1. A new array is a new page 1. */
- data: unknown;
infinite?: InfiniteOptions;
}): { count: number; isExact: boolean } {
const fetcher = useFetcher<{ count?: number; exactCount?: boolean }>();
@@ -42,12 +41,11 @@ export function useExactCount({
const load = useRef(fetcher.load);
load.current = fetcher.load;
- // biome-ignore lint/correctness/useExhaustiveDependencies: a new page 1 (`data`) counts again
useEffect(() => {
if (!wanted) return;
requestedKey.current = resetKey;
load.current(getCountUrl(pageUrl));
- }, [wanted, resetKey, pageUrl, data]);
+ }, [wanted, resetKey, pageUrl]);
useEffect(() => {
const result = fetcher.data;