@wordrhyme/auto-crud 1.21.2 → 1.21.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1747,6 +1747,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
1747
1747
  data,
1748
1748
  counts
1749
1749
  });
1750
+ const refreshPending = (0, react.useRef)(false);
1750
1751
  const refetchCounts = totals.refetch;
1751
1752
  (0, react.useEffect)(() => {
1752
1753
  const previous = previousSource.current;
@@ -1754,21 +1755,17 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
1754
1755
  data,
1755
1756
  counts
1756
1757
  };
1757
- if (previous.data === data && previous.counts === counts) return;
1758
- if (counts && ready && fieldsReady) client.cancelQueries({ queryKey: [
1759
- "auto-crud-view-counts",
1760
- config.cacheKey,
1761
- resourceId
1762
- ] }).then(() => refetchCounts());
1758
+ if (previous.data !== data || previous.counts !== counts) refreshPending.current = true;
1759
+ if (!counts || !ready || !fieldsReady || totals.fetchStatus !== "idle" || !refreshPending.current) return;
1760
+ refreshPending.current = false;
1761
+ refetchCounts({ cancelRefetch: false });
1763
1762
  }, [
1764
1763
  data,
1765
1764
  counts,
1766
1765
  ready,
1767
1766
  fieldsReady,
1768
- refetchCounts,
1769
- client,
1770
- config.cacheKey,
1771
- resourceId
1767
+ totals.fetchStatus,
1768
+ refetchCounts
1772
1769
  ]);
1773
1770
  const renderCount = (key) => {
1774
1771
  if (!counts) return null;
@@ -11854,6 +11851,7 @@ const defaultToastAdapter = {
11854
11851
  info: sonner.toast.info,
11855
11852
  warning: sonner.toast.warning
11856
11853
  };
11854
+ const EMPTY_ROWS = [];
11857
11855
  /** 空 toast 适配器(禁用通知) */
11858
11856
  const noopToastAdapter = {
11859
11857
  success: () => {},
@@ -12047,7 +12045,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
12047
12045
  if (listReady && listQuery.data !== void 0) hasReadyListData.current = true;
12048
12046
  }, [listReady, listQuery.data]);
12049
12047
  const listData = listReady ? listQuery.data : void 0;
12050
- const tableRows = listData?.data ?? [];
12048
+ const tableRows = listData?.data ?? EMPTY_ROWS;
12051
12049
  const createMutation = router.create.useMutation();
12052
12050
  const updateMutation = router.update.useMutation();
12053
12051
  const deleteMutation = router.delete.useMutation();
package/dist/index.js CHANGED
@@ -1731,6 +1731,7 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
1731
1731
  data,
1732
1732
  counts
1733
1733
  });
1734
+ const refreshPending = useRef(false);
1734
1735
  const refetchCounts = totals.refetch;
1735
1736
  useEffect(() => {
1736
1737
  const previous = previousSource.current;
@@ -1738,21 +1739,17 @@ function ViewMenu({ resourceId, table, fieldsReady = true, defaultView, presets,
1738
1739
  data,
1739
1740
  counts
1740
1741
  };
1741
- if (previous.data === data && previous.counts === counts) return;
1742
- if (counts && ready && fieldsReady) client.cancelQueries({ queryKey: [
1743
- "auto-crud-view-counts",
1744
- config.cacheKey,
1745
- resourceId
1746
- ] }).then(() => refetchCounts());
1742
+ if (previous.data !== data || previous.counts !== counts) refreshPending.current = true;
1743
+ if (!counts || !ready || !fieldsReady || totals.fetchStatus !== "idle" || !refreshPending.current) return;
1744
+ refreshPending.current = false;
1745
+ refetchCounts({ cancelRefetch: false });
1747
1746
  }, [
1748
1747
  data,
1749
1748
  counts,
1750
1749
  ready,
1751
1750
  fieldsReady,
1752
- refetchCounts,
1753
- client,
1754
- config.cacheKey,
1755
- resourceId
1751
+ totals.fetchStatus,
1752
+ refetchCounts
1756
1753
  ]);
1757
1754
  const renderCount = (key) => {
1758
1755
  if (!counts) return null;
@@ -11838,6 +11835,7 @@ const defaultToastAdapter = {
11838
11835
  info: toast.info,
11839
11836
  warning: toast.warning
11840
11837
  };
11838
+ const EMPTY_ROWS = [];
11841
11839
  /** 空 toast 适配器(禁用通知) */
11842
11840
  const noopToastAdapter = {
11843
11841
  success: () => {},
@@ -12031,7 +12029,7 @@ function useAutoCrudResource({ router, queryKeys, schema, query: queryTransform,
12031
12029
  if (listReady && listQuery.data !== void 0) hasReadyListData.current = true;
12032
12030
  }, [listReady, listQuery.data]);
12033
12031
  const listData = listReady ? listQuery.data : void 0;
12034
- const tableRows = listData?.data ?? [];
12032
+ const tableRows = listData?.data ?? EMPTY_ROWS;
12035
12033
  const createMutation = router.create.useMutation();
12036
12034
  const updateMutation = router.update.useMutation();
12037
12035
  const deleteMutation = router.delete.useMutation();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wordrhyme/auto-crud",
3
3
  "type": "module",
4
- "version": "1.21.2",
4
+ "version": "1.21.3",
5
5
  "description": "Schema-first CRUD components with auto-generated tables and forms",
6
6
  "author": "wordrhyme",
7
7
  "license": "MIT",
@@ -95,10 +95,10 @@
95
95
  "typescript": "^5.9.3",
96
96
  "vitest": "^3.2.4",
97
97
  "@internal/prettier-config": "0.0.1",
98
- "@internal/tsconfig": "0.1.0",
98
+ "@internal/eslint-config": "0.3.0",
99
99
  "@internal/tsdown-config": "0.1.0",
100
100
  "@internal/vitest-config": "0.1.0",
101
- "@internal/eslint-config": "0.3.0"
101
+ "@internal/tsconfig": "0.1.0"
102
102
  },
103
103
  "prettier": "@internal/prettier-config",
104
104
  "scripts": {