mirror of
https://github.com/docmost/docmost.git
synced 2026-08-25 15:57:11 +08:00
fix: drop stale results when the search content type changes
This commit is contained in:
@@ -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;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user