diff --git a/changelog/unreleased/bugfix-duplicated-file-search-request b/changelog/unreleased/bugfix-duplicated-file-search-request new file mode 100644 index 00000000000..60f013cf84d --- /dev/null +++ b/changelog/unreleased/bugfix-duplicated-file-search-request @@ -0,0 +1,6 @@ +Bugfix: Duplicated file search request + +We have fixed a bug where the search was sent unnecessarily twice. + +https://github.com/owncloud/web/pull/9861 +https://github.com/owncloud/web/issues/9787 diff --git a/packages/web-app-files/src/components/Search/List.vue b/packages/web-app-files/src/components/Search/List.vue index ec489f80daa..ad3125e8072 100644 --- a/packages/web-app-files/src/components/Search/List.vue +++ b/packages/web-app-files/src/components/Search/List.vue @@ -351,13 +351,26 @@ export default defineComponent({ watch( () => unref(route).query, (newVal, oldVal) => { - const filters = ['q_fullText', 'q_tags', 'q_lastModified', 'useScope'] - const isChange = - newVal?.term !== oldVal?.term || - filters.some((f) => newVal[f] ?? undefined !== oldVal[f] ?? undefined) - if (isChange && isLocationCommonActive(router, 'files-common-search')) { - emit('search', buildSearchTerm(true)) + // return early if this view is not active, no search needed + { + const isSearchViewActive = isLocationCommonActive(router, 'files-common-search') + if (!isSearchViewActive) { + return + } } + + // return early if the search term or filter has not changed, no search needed + { + const isSameTerm = newVal?.term === oldVal?.term + const isSameFilter = ['q_fullText', 'q_tags', 'q_lastModified', 'useScope'].every( + (key) => newVal[key] === oldVal[key] + ) + if (isSameTerm && isSameFilter) { + return + } + } + + emit('search', buildSearchTerm(true)) }, { deep: true } )