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 1b909c8352b..28c1090dde4 100644 --- a/packages/web-app-files/src/components/Search/List.vue +++ b/packages/web-app-files/src/components/Search/List.vue @@ -290,13 +290,26 @@ export default defineComponent({ watch( () => unref(route).query, (newVal, oldVal) => { - const filters = ['q_fullText', 'q_tags', '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 isSearchViewPainted = isLocationCommonActive(router, 'files-common-search') + if (!isSearchViewPainted) { + 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', 'useScope'].every( + (key) => newVal[key] === oldVal[key] + ) + if (isSameTerm && isSameFilter) { + return + } + } + + emit('search', buildSearchTerm(true)) }, { deep: true } )