Skip to content

Commit 7ffc5c4

Browse files
authored
fix(SchemaTree): prevent infinite loop (#2909)
1 parent f7e763d commit 7ffc5c4

File tree

3 files changed

+54
-47
lines changed

3 files changed

+54
-47
lines changed

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"use-query-params": "^2.2.1",
6060
"uuid": "^10.0.0",
6161
"web-vitals": "^1.1.2",
62-
"ydb-ui-components": "^5.1.0",
62+
"ydb-ui-components": "^5.1.1",
6363
"zod": "^3.24.1"
6464
},
6565
"scripts": {

src/containers/Tenant/ObjectSummary/SchemaTree/SchemaTree.tsx

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -60,50 +60,56 @@ export function SchemaTree(props: SchemaTreeProps) {
6060
? 'database'
6161
: mapPathTypeToNavigationTreeType(rootType);
6262

63-
const fetchPath = async (path: string) => {
64-
let schemaData: TEvDescribeSchemeResult | undefined;
65-
do {
66-
const promise = dispatch(
67-
schemaApi.endpoints.getSchema.initiate(
68-
{path, database, databaseFullPath},
69-
{forceRefetch: true},
70-
),
71-
);
72-
const {data, originalArgs} = await promise;
73-
promise.unsubscribe();
74-
// Check if the result from the current request is received. rtk-query may skip the current request and
75-
// return data from a parallel request, due to the same cache key.
76-
if (originalArgs?.path === path) {
77-
schemaData = data?.[path];
78-
break;
63+
const fetchPath = React.useCallback(
64+
async (path: string) => {
65+
let schemaData: TEvDescribeSchemeResult | undefined;
66+
67+
do {
68+
const promise = dispatch(
69+
schemaApi.endpoints.getSchema.initiate(
70+
{path, database, databaseFullPath},
71+
{forceRefetch: true},
72+
),
73+
);
74+
75+
const {data, originalArgs} = await promise;
76+
promise.unsubscribe();
77+
// Check if the result from the current request is reonceived. rtk-query may skip the current request and
78+
// return data from a parallel request, due to the same cache key.
79+
if (originalArgs?.path === path) {
80+
schemaData = data?.[path];
81+
break;
82+
}
83+
// eslint-disable-next-line no-constant-condition
84+
} while (true);
85+
86+
if (!schemaData) {
87+
throw new Error(`No describe data about path ${path}`);
7988
}
80-
// eslint-disable-next-line no-constant-condition
81-
} while (true);
8289

83-
if (!schemaData) {
84-
throw new Error(`no describe data about path ${path}`);
85-
}
86-
const {PathDescription: {Children = []} = {}} = schemaData;
87-
88-
const childItems = Children.map((childData) => {
89-
const {Name = '', PathType, PathSubType, ChildrenExist} = childData;
90-
91-
const isChildless =
92-
isChildlessPathType(PathType, PathSubType) ||
93-
(valueIsDefined(ChildrenExist) && !ChildrenExist);
94-
95-
return {
96-
name: Name,
97-
type: mapPathTypeToNavigationTreeType(PathType, PathSubType),
98-
// FIXME: should only be explicitly set to true for tables with indexes
99-
// at the moment of writing there is no property to determine this, fix later
100-
expandable: !isChildless,
101-
meta: {subType: PathSubType},
102-
};
103-
});
104-
105-
return childItems;
106-
};
90+
const {PathDescription: {Children = []} = {}} = schemaData;
91+
92+
const childItems = Children.map((childData) => {
93+
const {Name = '', PathType, PathSubType, ChildrenExist} = childData;
94+
95+
const isChildless =
96+
isChildlessPathType(PathType, PathSubType) ||
97+
(valueIsDefined(ChildrenExist) && !ChildrenExist);
98+
99+
return {
100+
name: Name,
101+
type: mapPathTypeToNavigationTreeType(PathType, PathSubType),
102+
// FIXME: should only be explicitly set to true for tables with indexes
103+
// at the moment of writing there is no property to determine this, fix later
104+
expandable: !isChildless,
105+
meta: {subType: PathSubType},
106+
};
107+
});
108+
109+
return childItems;
110+
},
111+
[dispatch, database, databaseFullPath],
112+
);
107113
React.useEffect(() => {
108114
// if the cached path is not in the current tree, show root
109115
if (!currentPath?.startsWith(databaseFullPath)) {

0 commit comments

Comments
 (0)