From a1ae9b2227cce30ec3b1d158c5438cd00449ffef Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 24 Aug 2026 22:07:53 +0100 Subject: [PATCH] fix: drop stale results when the search content type changes --- .../src/features/search/hooks/use-unified-search.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/client/src/features/search/hooks/use-unified-search.ts b/apps/client/src/features/search/hooks/use-unified-search.ts index 592e74fac..156c711d8 100644 --- a/apps/client/src/features/search/hooks/use-unified-search.ts +++ b/apps/client/src/features/search/hooks/use-unified-search.ts @@ -1,4 +1,4 @@ -import { keepPreviousData, useQuery, UseQueryResult } from "@tanstack/react-query"; +import { useQuery, UseQueryResult } from "@tanstack/react-query"; import { searchPage, searchAttachments, @@ -40,6 +40,14 @@ export function useUnifiedSearch( } }, enabled: !!params.query && enabled, - placeholderData: params.query.length > 0 ? keepPreviousData: undefined + // keep previous results only within the same search type; page results + // rendered as attachments (or vice versa) crash on missing fields + placeholderData: (previousData, previousQuery) => { + if (params.query.length < 1) return undefined; + if (previousQuery && previousQuery.queryKey[1] !== searchType) { + return undefined; + } + return previousData; + }, }); }