fix: avoid infinite loop
This commit is contained in:
parent
976b094f96
commit
9a1794a932
@ -1,5 +1,6 @@
|
|||||||
import { clone } from '@formily/shared';
|
import { clone } from '@formily/shared';
|
||||||
import { CascaderProps } from 'antd';
|
import { CascaderProps } from 'antd';
|
||||||
|
import _ from 'lodash';
|
||||||
import { reduce, unionBy, uniq, uniqBy } from 'lodash';
|
import { reduce, unionBy, uniq, uniqBy } from 'lodash';
|
||||||
import { useContext } from 'react';
|
import { useContext } from 'react';
|
||||||
import { useCompile } from '../../schema-component';
|
import { useCompile } from '../../schema-component';
|
||||||
@ -81,6 +82,9 @@ export const useCollectionManager = () => {
|
|||||||
return collection?.fields || [];
|
return collection?.fields || [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 缓存下面已经获取的 options,防止无限循环
|
||||||
|
const cachedOptions = {};
|
||||||
|
|
||||||
const getCollectionFieldsOptions = (
|
const getCollectionFieldsOptions = (
|
||||||
collectionName: string,
|
collectionName: string,
|
||||||
type: string | string[] = 'string',
|
type: string | string[] = 'string',
|
||||||
@ -92,6 +96,11 @@ export const useCollectionManager = () => {
|
|||||||
association?: boolean | string[];
|
association?: boolean | string[];
|
||||||
},
|
},
|
||||||
) => {
|
) => {
|
||||||
|
// 防止无限循环
|
||||||
|
if (cachedOptions[collectionName]) {
|
||||||
|
return _.cloneDeep(cachedOptions[collectionName]);
|
||||||
|
}
|
||||||
|
|
||||||
const { association = false } = opts || {};
|
const { association = false } = opts || {};
|
||||||
if (typeof type === 'string') {
|
if (typeof type === 'string') {
|
||||||
type = [type];
|
type = [type];
|
||||||
@ -122,6 +131,7 @@ export const useCollectionManager = () => {
|
|||||||
// 过滤 map 产生为 null 的数据
|
// 过滤 map 产生为 null 的数据
|
||||||
.filter(Boolean);
|
.filter(Boolean);
|
||||||
|
|
||||||
|
cachedOptions[collectionName] = options;
|
||||||
return options;
|
return options;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user