@izumisy-tailor/tailor-data-viewer 0.1.7 → 0.1.8
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/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, useEffect } from "react";
|
|
1
|
+
import { useState, useEffect, useMemo } from "react";
|
|
2
2
|
import { GraphQLClient } from "graphql-request";
|
|
3
3
|
import type { TableMetadata } from "../../generator/metadata-generator";
|
|
4
4
|
|
|
@@ -23,6 +23,11 @@ export function useTableAccessCheck(
|
|
|
23
23
|
const [isLoading, setIsLoading] = useState(true);
|
|
24
24
|
const [error, setError] = useState<string | null>(null);
|
|
25
25
|
|
|
26
|
+
// Memoize tables to prevent infinite loops
|
|
27
|
+
// when the parent component passes a new array reference on each render
|
|
28
|
+
const tableKey = tables.map((t) => t.name).join(",");
|
|
29
|
+
const stableTables = useMemo(() => tables, [tableKey]);
|
|
30
|
+
|
|
26
31
|
useEffect(() => {
|
|
27
32
|
let cancelled = false;
|
|
28
33
|
|
|
@@ -39,7 +44,7 @@ export function useTableAccessCheck(
|
|
|
39
44
|
});
|
|
40
45
|
|
|
41
46
|
const results = await Promise.allSettled(
|
|
42
|
-
|
|
47
|
+
stableTables.map(async (table) => {
|
|
43
48
|
// Execute a lightweight aggregate query to check access
|
|
44
49
|
const query = `query CheckAccess { ${table.pluralForm}(query: {}) { total } }`;
|
|
45
50
|
await client.request(query);
|
|
@@ -73,7 +78,7 @@ export function useTableAccessCheck(
|
|
|
73
78
|
return () => {
|
|
74
79
|
cancelled = true;
|
|
75
80
|
};
|
|
76
|
-
}, [
|
|
81
|
+
}, [stableTables, appUri]);
|
|
77
82
|
|
|
78
83
|
return { accessibleTables, isLoading, error };
|
|
79
84
|
}
|