Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

MUL-7546 fix(issues): preserve identifier lookups across remounts (#8622)

LinYushenf8c90a31d457
diff --git a/packages/core/api/client.ts b/packages/core/api/client.ts
index 99d5d3e0d4..5eac0b1ca9 100644
--- a/packages/core/api/client.ts
+++ b/packages/core/api/client.ts
@@ -1215,8 +1215,8 @@ export class ApiClient {
* unique `(workspace_id, number)` index, and 404s on a wrong prefix or a
* missing number.
*
- * `signal` is optional so cancel-on-unmount callers (identifier autolink
- * resolution) can abort an in-flight lookup the same way search does.
+ * `signal` remains optional for callers that need to abort an in-flight
+ * lookup; identifier autolink resolution intentionally lets it complete.
*
* The 2xx body is validated, not cast. A single issue is not a list: there
* is no safe-empty shape to degrade to, and the identifier-autolink caller
diff --git a/packages/core/issues/queries.test.ts b/packages/core/issues/queries.test.ts
index a8b2fdcb4f..92470aa575 100644
--- a/packages/core/issues/queries.test.ts
+++ b/packages/core/issues/queries.test.ts
@@ -1,3 +1,4 @@
+// @vitest-environment node
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { QueryClient, QueryObserver } from "@tanstack/react-query";
@@ -555,16 +556,51 @@ describe("issueIdentifierOptions", () => {
).rejects.toThrow("boom");
});
- it("passes the query's abort signal down so unmount cancels the lookup", async () => {
- const getIssue = vi
- .fn<(id: string, options?: { signal?: AbortSignal }) => Promise<Issue>>()
- .mockResolvedValue(makeIssue(7));
- installFakeIssueApi(getIssue);
-
- await qc.fetchQuery(issueIdentifierOptions(WS_ID, "MUL-7"));
-
- expect(getIssue.mock.calls[0]?.[1]?.signal).toBeInstanceOf(AbortSignal);
- });
+ it.each(["found", "missing"] as const)(
+ "shares a pending %s lookup across rapid observer remounts and caches its result",
+ async (outcome) => {
+ let resolveLookup!: (issue: Issue) => void;
+ let rejectLookup!: (error: Error) => void;
+ let abortedLookups = 0;
+ const getIssue = vi
+ .fn<(id: string, options?: { signal?: AbortSignal }) => Promise<Issue>>()
+ .mockImplementation((_id, options) => new Promise((resolve, reject) => {
+ resolveLookup = resolve;
+ rejectLookup = reject;
+ options?.signal?.addEventListener("abort", () => {
+ abortedLookups++;
+ reject(new DOMException("Unmounted", "AbortError"));
+ }, { once: true });
+ }));
+ installFakeIssueApi(getIssue);
+
+ const options = issueIdentifierOptions(WS_ID, "MUL-7");
+ // Streaming rich content can remove the last mention observer before
+ // its response arrives, then render that same identifier again.
+ for (let i = 0; i < 20; i++) {
+ const observer = new QueryObserver(qc, options);
+ const unsubscribe = observer.subscribe(() => {});
+ unsubscribe();
+ }
+
+ expect(getIssue).toHaveBeenCalledTimes(1);
+ expect(abortedLookups).toBe(0);
+ const completed = qc.fetchQuery(options);
+ if (outcome === "found") {
+ resolveLookup(makeIssue(7));
+ } else {
+ rejectLookup(new ApiError("issue not found", 404, "Not Found"));
+ }
+ const expected = outcome === "found" ? makeIssue(7) : null;
+ await expect(completed).resolves.toEqual(expected);
+
+ const observer = new QueryObserver(qc, options);
+ const unsubscribe = observer.subscribe(() => {});
+ expect(observer.getCurrentResult().data).toEqual(expected);
+ expect(getIssue).toHaveBeenCalledTimes(1);
+ unsubscribe();
+ },
+ );
it("keys the query by workspace and identifier", () => {
expect(issueKeys.identifier(WS_ID, "MUL-7")).toEqual([
diff --git a/packages/core/issues/queries.ts b/packages/core/issues/queries.ts
index 706fb1a535..b8366a61fd 100644
--- a/packages/core/issues/queries.ts
+++ b/packages/core/issues/queries.ts
@@ -460,13 +460,15 @@ export function issueDetailOptions(wsId: string, id: string) {
export function issueIdentifierOptions(wsId: string, identifier: string) {
return queryOptions({
queryKey: issueKeys.identifier(wsId, identifier),
- queryFn: async ({ signal }) => {
+ // Keep this small, cacheable lookup alive when the last mention unmounts.
+ // A remount can then share its request instead of aborting and restarting it.
+ queryFn: async () => {
try {
- return await api.getIssue(identifier, { signal });
+ return await api.getIssue(identifier);
} catch (err) {
// Unknown identifier / wrong workspace prefix → render as plain text.
- // Any other failure (401/5xx/abort) must keep propagating so the query
- // is retried or cancelled instead of being cached as "no such issue".
+ // Any other failure (401/5xx) must keep propagating so the query
+ // can retry instead of being cached as "no such issue".
if (err instanceof ApiError && err.status === 404) return null;
throw err;
}