mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 00:12:39 +00:00
fix: stop waiting for plugin search results when the search fails
This commit is contained in:
@@ -150,6 +150,22 @@ describe('onProvideSearchResults', () => {
|
||||
expect(useEmailStore.getState().externalSearchPending).toEqual([]);
|
||||
});
|
||||
|
||||
it('waits no more for the plugins of a search that failed', async () => {
|
||||
const answer = deferred<ExternalSearchResult[]>();
|
||||
emailHooks.onProvideSearchResults.register('crm', () => answer.promise);
|
||||
vi.mocked(client.searchEmails).mockRejectedValueOnce(new Error('boom'));
|
||||
|
||||
await useEmailStore.getState().searchEmails(client, 'resolution');
|
||||
expect(useEmailStore.getState().error).toBe('boom');
|
||||
expect(useEmailStore.getState().externalSearchPending).toEqual([]);
|
||||
|
||||
answer.resolve([entry('late')]);
|
||||
await answer.promise;
|
||||
await new Promise((r) => setTimeout(r, 0));
|
||||
expect(useEmailStore.getState().externalSearchResults).toEqual([]);
|
||||
expect(useEmailStore.getState().externalSearchPending).toEqual([]);
|
||||
});
|
||||
|
||||
it('waits no more for the plugins of a search that was replaced', async () => {
|
||||
emailHooks.onProvideSearchResults.register('crm', (_results: ExternalSearchResult[], { query }: { query: string }) =>
|
||||
(query === 'one' ? new Promise(() => {}) : [entry('two')]));
|
||||
|
||||
@@ -5353,12 +5353,15 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
|
||||
highlightWhenSnippetsArrive('snippets' in result ? result.snippets : undefined);
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted) return;
|
||||
// Plugins still answering this search have nothing to add to an error.
|
||||
providedSearchRun = null;
|
||||
set({
|
||||
error: error instanceof Error ? error.message : "Failed to search emails",
|
||||
searchQuery: typedQuery,
|
||||
isLoading: false,
|
||||
emails: [],
|
||||
externalSearchResults: [],
|
||||
externalSearchPending: [],
|
||||
hasMoreEmails: false,
|
||||
totalEmails: 0,
|
||||
searchAbortController: null,
|
||||
@@ -5465,11 +5468,14 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
|
||||
highlightWhenSnippetsArrive('snippets' in result ? result.snippets : undefined);
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted) return;
|
||||
// Plugins still answering this search have nothing to add to an error.
|
||||
providedSearchRun = null;
|
||||
set({
|
||||
error: error instanceof Error ? error.message : "Failed to search emails",
|
||||
isLoading: false,
|
||||
emails: [],
|
||||
externalSearchResults: [],
|
||||
externalSearchPending: [],
|
||||
hasMoreEmails: false,
|
||||
totalEmails: 0,
|
||||
searchAbortController: null,
|
||||
|
||||
Reference in New Issue
Block a user