From c49044042493a58a0238b40315c6f525c6bc0d28 Mon Sep 17 00:00:00 2001 From: hayyaksi <193020925+hayaksi1@users.noreply.github.com> Date: Wed, 12 Aug 2026 14:18:33 +0300 Subject: [PATCH] Stop reporting a search you cancelled yourself as a failure (#34594) Opening a search result aborts the search, which rejects whatever request is still in flight. The rejection lands in the same handler as a real failure, so the user was shown a "Search failed: signal is aborted without reason" dialog for doing nothing more than clicking a result. There is a guard for this already, but it only covers the case where the component has come apart first: `aborted` is set by the unmount cleanup, and the rejection often arrives before React gets that far. An AbortError is now recognised for what it is and dropped, whichever way round the two happen to land. Nothing else changes: a rejection from any other cause still reaches the error dialog, since that is a failure nobody asked for. Tests: a search rejected with an AbortError no longer reports an error, and one rejected with anything else still does. Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- .../components/structures/RoomSearchView.tsx | 8 ++++++ .../structures/RoomSearchView-test.tsx | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/apps/web/src/components/structures/RoomSearchView.tsx b/apps/web/src/components/structures/RoomSearchView.tsx index bfd800e7d9..8892b197a3 100644 --- a/apps/web/src/components/structures/RoomSearchView.tsx +++ b/apps/web/src/components/structures/RoomSearchView.tsx @@ -119,6 +119,14 @@ export const RoomSearchView = ({ term, scope, promise, className, onUpdate, inPr logger.error("Discarding stale search results"); return false; } + if (error?.name === "AbortError") { + // Opening a result aborts the search, which rejects whatever request is + // still in flight. We asked for that, so there is nothing to tell the user + // about — and the rejection can reach us before the unmount which would + // otherwise have set `aborted`. + debuglog("search aborted"); + return false; + } logger.error("Search failed", error); onUpdate(false, null, error); return false; diff --git a/apps/web/test/unit-tests/components/structures/RoomSearchView-test.tsx b/apps/web/test/unit-tests/components/structures/RoomSearchView-test.tsx index dccf608003..b9dbe9841c 100644 --- a/apps/web/test/unit-tests/components/structures/RoomSearchView-test.tsx +++ b/apps/web/test/unit-tests/components/structures/RoomSearchView-test.tsx @@ -330,6 +330,33 @@ describe("", () => { expect(onUpdate).toHaveBeenCalledTimes(2); }); + it("does not report an aborted search as an error", async () => { + const onUpdate = jest.fn(); + const deferred = Promise.withResolvers(); + + render( + + + , + ); + // What fetch rejects with when RoomView aborts the search to open one of its results. + deferred.reject(new DOMException("signal is aborted without reason", "AbortError")); + try { + // Wait for RoomSearchView to process the promise + await deferred.promise; + } catch {} + + expect(onUpdate).toHaveBeenCalledTimes(1); + expect(onUpdate).toHaveBeenCalledWith(true, null, null); + }); + it("should combine search results when the query is present in multiple sucessive messages", async () => { const searchResults: ISearchResults = { results: [