Skip to content

Commit

Permalink
fix(pro:search): key duplication after controlled value change (#1708)
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Oct 7, 2023
1 parent 840eefe commit 3ae8dd2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions packages/pro/search/src/composables/useSearchStates.ts
Expand Up @@ -244,10 +244,18 @@ export function useSearchStates(
const createdStates = getMarks()
.map(({ key, mark }) => mark === 'created' && getSearchStateByKey(key))
.filter(Boolean)
.map((state, index) => ({
...state,
index: lastIndex + index + 1,
})) as SearchState[]
.map((state, index) => {
// recreate the state key again to avoid key duplication
const fieldKey = (state as SearchState).fieldKey
const count = dataKeyCountMap.has(fieldKey) ? dataKeyCountMap.get(fieldKey)! : 0
const key = getKey(fieldKey, count)

return {
...state,
key,
index: lastIndex + index + 1,
}
}) as SearchState[]

searchStates.value = [...newSearchStates, ...createdStates]
}
Expand Down

0 comments on commit 3ae8dd2

Please sign in to comment.