Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7906: fix(issues): use navigation hash for comment deep links (#9112)
2penheimer84e4ac8cc8ab
diff --git a/packages/views/issues/components/issue-detail-route-comment-links.test.tsx b/packages/views/issues/components/issue-detail-route-comment-links.test.tsxnew file mode 100644index 0000000000..6b5a3c5451--- /dev/null+++ b/packages/views/issues/components/issue-detail-route-comment-links.test.tsx@@ -0,0 +1,111 @@+import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";+import { render, waitFor } from "@testing-library/react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import { setApiInstance } from "@multica/core/api";+import type { ApiClient } from "@multica/core/api/client";+import { NavigationProvider } from "../../navigation";+import { IssueDetail } from "./issue-detail";+import { IssueDetailRoute } from "./issue-detail-route";++vi.mock("./issue-detail", async () => {+ const actual = await vi.importActual<typeof import("./issue-detail")>("./issue-detail");+ return { ...actual, IssueDetail: vi.fn(() => null) };+});++vi.mock("@multica/core/hooks", () => ({+ useWorkspaceId: () => "ws-1",+}));++vi.mock("@multica/core/paths", async () => {+ const actual = await vi.importActual<typeof import("@multica/core/paths")>(+ "@multica/core/paths",+ );+ return {+ ...actual,+ useCurrentWorkspace: () => ({ id: "ws-1", name: "Acme", slug: "acme" }),+ useWorkspacePaths: () => actual.paths.workspace("acme"),+ };+});++const replace = vi.fn();+const push = vi.fn();++describe("IssueDetailRoute comment deep links", () => {+ const issueId = "cb240efb-154c-42a8-ae92-42b02676feca";+ let qc: QueryClient;++ beforeEach(() => {+ replace.mockClear();+ push.mockClear();+ vi.mocked(IssueDetail).mockClear();+ // Electron's browser location need not match the active tab's location.+ window.history.replaceState(null, "", "/#comment-browser-comment");+ setApiInstance({+ getIssue: vi.fn().mockResolvedValue({ id: issueId, identifier: "TRS-134" }),+ } as unknown as ApiClient);+ qc = new QueryClient({+ defaultOptions: { queries: { staleTime: Infinity, retry: false } },+ });+ });++ afterEach(() => {+ qc.clear();+ window.history.replaceState(null, "", "/");+ });++ function route(hash: string, routeId = "TRS-134") {+ return (+ <QueryClientProvider client={qc}>+ <NavigationProvider+ value={{+ push,+ replace,+ back: vi.fn(),+ pathname: `/acme/issues/${routeId}`,+ searchParams: new URLSearchParams(),+ hash,+ getShareableUrl: (p: string) => `https://app.multica.com${p}`,+ }}+ >+ <IssueDetailRoute routeId={routeId} />+ </NavigationProvider>+ </QueryClientProvider>+ );+ }++ function expectHighlight(commentId: string | undefined) {+ expect(vi.mocked(IssueDetail).mock.lastCall?.[0]).toMatchObject({+ issueId,+ highlightCommentId: commentId,+ });+ }++ it("highlights the adapter comment instead of the browser fragment", async () => {+ render(route("#comment-adapter-comment"));+ await waitFor(() => expectHighlight("adapter-comment"));+ expect(replace).not.toHaveBeenCalled();+ });++ it("retains the adapter fragment when canonicalizing a UUID route", async () => {+ render(route("#comment-adapter-comment", issueId));+ await waitFor(() => {+ expectHighlight("adapter-comment");+ expect(replace).toHaveBeenCalledWith("/acme/issues/TRS-134#comment-adapter-comment");+ });+ expect(push).not.toHaveBeenCalled();+ });++ it("updates the highlight when only the adapter hash changes", async () => {+ const { rerender } = render(route("#comment-first"));+ await waitFor(() => expect(IssueDetail).toHaveBeenCalled());+ rerender(route("#comment-second"));+ expectHighlight("second");+ });++ it.each(["", "#activity"])("clears the highlight for adapter hash %j", async (hash) => {+ const { rerender } = render(route("#comment-first"));+ await waitFor(() => expect(IssueDetail).toHaveBeenCalled());+ rerender(route(hash));+ expectHighlight(undefined);+ });+});diff --git a/packages/views/issues/components/issue-detail-route.test.tsx b/packages/views/issues/components/issue-detail-route.test.tsxindex a4dd17d07e..ef47514e07 100644--- a/packages/views/issues/components/issue-detail-route.test.tsx+++ b/packages/views/issues/components/issue-detail-route.test.tsx@@ -6,6 +6,7 @@ import { setApiInstance } from "@multica/core/api";import type { ApiClient } from "@multica/core/api/client";import { NavigationProvider } from "../../navigation";import type { NavigationAdapter } from "../../navigation";+import { IssueDetail } from "./issue-detail";import {IssueDetailRoute,parseCommentHighlightHash,@@ -123,6 +124,7 @@ describe("IssueDetailRoute with an identifier that names no issue", () => {// failed — an unbounded request loop that never reached "not found".// Retry is off so any count above 1 can only be a remount refetch.it("settles on not-found without looping requests", async () => {+ expect(vi.isMockFunction(IssueDetail)).toBe(false);replace.mockClear();push.mockClear();const getIssue = vi.fn().mockRejectedValue(new Error("issue not found"));diff --git a/packages/views/issues/components/issue-detail-route.tsx b/packages/views/issues/components/issue-detail-route.tsxindex 39bbd5a3d2..2eac0627bf 100644--- a/packages/views/issues/components/issue-detail-route.tsx+++ b/packages/views/issues/components/issue-detail-route.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useRef, useState } from "react";+import { useEffect, useRef } from "react";import { useCanonicalIssue } from "@multica/core/issues/canonical-id";import { useWorkspaceId } from "@multica/core/hooks";import { useWorkspacePaths } from "@multica/core/paths";@@ -52,14 +52,7 @@ export function parseCommentHighlightHash(hash: string): string | undefined {}function useCommentHighlightHash(): { hash: string; commentId?: string } {- const read = () => typeof window === "undefined" ? "" : window.location.hash;- const [hash, setHash] = useState(read);-- useEffect(() => {- const onHashChange = () => setHash(read());- window.addEventListener("hashchange", onHashChange);- return () => window.removeEventListener("hashchange", onHashChange);- }, []);+ const { hash } = useNavigation();return { hash, commentId: parseCommentHighlightHash(hash) };}