Skip to content

Commit 1dd2ccc

Browse files
authoredMar 19, 2024
fix: use more reliable comparison in deduping search results (#6034)
1 parent a58b596 commit 1dd2ccc

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed
 

‎packages/sanity/src/core/studio/components/navbar/search/datastores/recentSearches.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {type ObjectSchemaType, type Schema} from '@sanity/types'
2-
import omit from 'lodash/omit'
2+
import {isEqual, omit} from 'lodash'
33
import {useMemo} from 'react'
44

55
import {useSchema} from '../../../../../hooks'
@@ -112,13 +112,12 @@ export function useRecentSearchesStore(): RecentSearchesStore {
112112
}
113113
// Add new search item, remove previous duplicates (if any) and truncate array.
114114
// When comparing search items, don't compare against the created date (which will always be different).
115-
const comparator = JSON.stringify(omit(newSearchItem, 'created'))
116115
const newRecent: StoredSearch = {
117116
version: RECENT_SEARCH_VERSION,
118117
recentSearches: [
119118
newSearchItem,
120119
...storedSearch.recentSearches.filter((r) => {
121-
return JSON.stringify(omit(r, 'created')) !== comparator
120+
return !isEqual(omit(r, 'created'), omit(newSearchItem, 'created'))
122121
}),
123122
].slice(0, MAX_RECENT_SEARCHES),
124123
}

0 commit comments

Comments
 (0)
Please sign in to comment.