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>
This commit is contained in:
hayyaksi
2026-08-12 14:18:33 +03:00
committed by GitHub
parent c08f235ea8
commit c490440424
2 changed files with 35 additions and 0 deletions
@@ -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;
@@ -330,6 +330,33 @@ describe("<RoomSearchView/>", () => {
expect(onUpdate).toHaveBeenCalledTimes(2);
});
it("does not report an aborted search as an error", async () => {
const onUpdate = jest.fn();
const deferred = Promise.withResolvers<ISearchResults>();
render(
<MatrixClientContext.Provider value={client}>
<RoomSearchView
inProgress={false}
term="search term"
scope={SearchScope.All}
promise={deferred.promise}
className="someClass"
onUpdate={onUpdate}
/>
</MatrixClientContext.Provider>,
);
// 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: [