diff --git a/packages/core/client/src/filter-provider/FilterProvider.tsx b/packages/core/client/src/filter-provider/FilterProvider.tsx index 66cc804fe4..6e4937d34a 100644 --- a/packages/core/client/src/filter-provider/FilterProvider.tsx +++ b/packages/core/client/src/filter-provider/FilterProvider.tsx @@ -5,6 +5,7 @@ import { SharedFilter, mergeFilter } from '../block-provider/SharedFilterProvide import { CollectionFieldOptions, useCollection } from '../collection-manager'; import { removeNullCondition } from '../schema-component'; import { useAssociatedFields } from './utils'; +import { uniqBy } from 'lodash'; type Collection = ReturnType; @@ -133,8 +134,8 @@ export const useFilterBlock = () => { existingBlock.defaultFilter = block.defaultFilter; return; } - - setDataBlocks((prev) => [...prev, block]); + // 由于 setDataBlocks 是异步操作,所以上面的 existingBlock 在判断时有可能用的是旧的 dataBlocks,所以下面还需要根据 uid 进行去重操作 + setDataBlocks((prev) => uniqBy([...prev, block], 'uid')); }; const getDataBlocks = () => dataBlocks; const removeDataBlock = (uid: string) => {