Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(settings): open issue links in new tab by default, configurable in preferences (#5445)
Jiayuan Zhang50e28d539c34
diff --git a/packages/core/issues/stores/index.ts b/packages/core/issues/stores/index.tsindex b52161a021..b953441755 100644--- a/packages/core/issues/stores/index.ts+++ b/packages/core/issues/stores/index.ts@@ -22,6 +22,7 @@ export {selectExpandedResolved,} from "./resolved-expand-store";export { useCommentComposerStore } from "./comment-composer-store";+export { useIssueLinkStore } from "./issue-link-store";export { useCommentDraftStore, type CommentDraftKey } from "./comment-draft-store";export {myIssuesViewStore,diff --git a/packages/core/issues/stores/issue-link-store.test.ts b/packages/core/issues/stores/issue-link-store.test.tsnew file mode 100644index 0000000000..188c3cc89b--- /dev/null+++ b/packages/core/issues/stores/issue-link-store.test.ts@@ -0,0 +1,40 @@+// @vitest-environment jsdom+import { beforeAll, beforeEach, describe, expect, it } from "vitest";+import { useIssueLinkStore } from "./issue-link-store";++// Node 25 ships a partial `localStorage` shim under jsdom that's missing+// `clear`/`removeItem`; replace it with a real in-memory Storage so persist+// can round-trip values.+beforeAll(() => {+ if (typeof globalThis.localStorage?.setItem !== "function") {+ const values = new Map<string, string>();+ const storage: Storage = {+ get length() { return values.size; },+ clear: () => values.clear(),+ getItem: (k) => values.get(k) ?? null,+ key: (i) => Array.from(values.keys())[i] ?? null,+ removeItem: (k) => { values.delete(k); },+ setItem: (k, v) => { values.set(k, v); },+ };+ Object.defineProperty(globalThis, "localStorage", { configurable: true, value: storage });+ Object.defineProperty(window, "localStorage", { configurable: true, value: storage });+ }+});++describe("issue link store", () => {+ beforeEach(() => {+ useIssueLinkStore.setState({ openInNewTab: true });+ });++ it("defaults to opening issue links in a new tab", () => {+ expect(useIssueLinkStore.getState().openInNewTab).toBe(true);+ });++ it("setOpenInNewTab switches to in-place navigation and back", () => {+ useIssueLinkStore.getState().setOpenInNewTab(false);+ expect(useIssueLinkStore.getState().openInNewTab).toBe(false);++ useIssueLinkStore.getState().setOpenInNewTab(true);+ expect(useIssueLinkStore.getState().openInNewTab).toBe(true);+ });+});diff --git a/packages/core/issues/stores/issue-link-store.ts b/packages/core/issues/stores/issue-link-store.tsnew file mode 100644index 0000000000..0f3f672330--- /dev/null+++ b/packages/core/issues/stores/issue-link-store.ts@@ -0,0 +1,31 @@+import { create } from "zustand";+import { createJSONStorage, persist } from "zustand/middleware";+import { defaultStorage } from "../../platform/storage";++/**+ * How issue mention links inside content (issue descriptions, comments,+ * chat markdown) open on plain click.+ *+ * `openInNewTab: true` (default) opens the linked issue in a new tab — a+ * browser tab on web, an app tab on desktop — so the reader keeps their+ * place in the issue they came from. `false` navigates in place. It's a+ * personal reading-ergonomics preference (like theme), so it persists+ * globally via `defaultStorage` rather than per-workspace storage.+ */+interface IssueLinkStore {+ openInNewTab: boolean;+ setOpenInNewTab: (open: boolean) => void;+}++export const useIssueLinkStore = create<IssueLinkStore>()(+ persist(+ (set) => ({+ openInNewTab: true,+ setOpenInNewTab: (open) => set({ openInNewTab: open }),+ }),+ {+ name: "multica_issue_link",+ storage: createJSONStorage(() => defaultStorage),+ },+ ),+);diff --git a/packages/views/editor/extensions/mention-view.tsx b/packages/views/editor/extensions/mention-view.tsxindex 7d3da435af..c64db67b36 100644--- a/packages/views/editor/extensions/mention-view.tsx+++ b/packages/views/editor/extensions/mention-view.tsx@@ -17,6 +17,7 @@import { NodeViewWrapper } from "@tiptap/react";import type { NodeViewProps } from "@tiptap/react";import { useWorkspacePaths } from "@multica/core/paths";+import { useIssueLinkStore } from "@multica/core/issues/stores";import { useNavigation } from "../../navigation";import { IssueChip } from "../../issues/components/issue-chip";import { ProjectChip } from "../../projects/components/project-chip";@@ -88,20 +89,39 @@ function IssueMention({}) {const p = useWorkspacePaths();const { push, openInNewTab } = useNavigation();+ const newTabPreferred = useIssueLinkStore((s) => s.openInNewTab);const issuePath = p.issueDetail(issueId);const handleClick = (e: React.MouseEvent) => {- e.preventDefault();e.stopPropagation();if (e.metaKey || e.ctrlKey || e.shiftKey) {- if (openInNewTab) openInNewTab(issuePath, fallbackLabel);+ if (openInNewTab) {+ e.preventDefault();+ openInNewTab(issuePath, fallbackLabel);+ }+ // Web: no adapter — native modifier-click on the anchor opens a tab.+ return;+ }+ if (newTabPreferred) {+ if (openInNewTab) {+ e.preventDefault();+ openInNewTab(issuePath, fallbackLabel, { activate: true });+ }+ // Web: native target="_blank" opens a browser tab.return;}+ e.preventDefault();push(issuePath);};return (- <a href={issuePath} onClick={handleClick} className="issue-mention">+ <a+ href={issuePath}+ target={newTabPreferred ? "_blank" : undefined}+ rel={newTabPreferred ? "noopener noreferrer" : undefined}+ onClick={handleClick}+ className="issue-mention"+ ><IssueChipissueId={issueId}fallbackLabel={fallbackLabel}diff --git a/packages/views/editor/readonly-content.tsx b/packages/views/editor/readonly-content.tsxindex 58d71476a8..c31f4d953e 100644--- a/packages/views/editor/readonly-content.tsx+++ b/packages/views/editor/readonly-content.tsx@@ -131,25 +131,15 @@ function urlTransform(url: string): string {// Custom react-markdown components// ---------------------------------------------------------------------------+/**+ * Issue mention chip. Navigation — plain click, modifier click, and the+ * "open issue links in new tab" preference — is owned by the AppLink inside+ * IssueMentionCard; the wrapper only shields surrounding click handlers+ * (e.g. collapsed-comment expanders) from mention clicks.+ */function IssueMentionLink({ issueId, label }: { issueId: string; label?: string }) {- const { push, openInNewTab } = useNavigation();- const p = useWorkspacePaths();- const path = p.issueDetail(issueId);return (- <span- className="inline align-middle"- onClick={(e) => {- e.preventDefault();- e.stopPropagation();- if (e.metaKey || e.ctrlKey || e.shiftKey) {- if (openInNewTab) {- openInNewTab(path, label);- }- return;- }- push(path);- }}- >+ <span className="inline align-middle" onClick={(e) => e.stopPropagation()}><IssueMentionCard issueId={issueId} fallbackLabel={label} /></span>);diff --git a/packages/views/issues/components/issue-mention-card.test.tsx b/packages/views/issues/components/issue-mention-card.test.tsxnew file mode 100644index 0000000000..040425687f--- /dev/null+++ b/packages/views/issues/components/issue-mention-card.test.tsx@@ -0,0 +1,97 @@+import { beforeEach, describe, expect, it, vi } from "vitest";+import { fireEvent, render, screen } from "@testing-library/react";+import { IssueMentionCard } from "./issue-mention-card";+import { NavigationProvider } from "../../navigation";+import type { NavigationAdapter } from "../../navigation";++const { issueLinkState } = vi.hoisted(() => ({+ issueLinkState: { openInNewTab: true, setOpenInNewTab: vi.fn() },+}));++vi.mock("@multica/core/issues/stores", () => {+ const useIssueLinkStore = (+ selector?: (s: typeof issueLinkState) => unknown,+ ) => (selector ? selector(issueLinkState) : issueLinkState);+ useIssueLinkStore.getState = () => issueLinkState;+ return { useIssueLinkStore };+});++vi.mock("@multica/core/paths", () => ({+ useWorkspacePaths: () => ({+ issueDetail: (id: string) => `/acme/issues/${id}`,+ }),+}));++vi.mock("./issue-chip", () => ({+ IssueChip: ({ fallbackLabel }: { fallbackLabel?: string }) => (+ <span data-testid="issue-chip">{fallbackLabel ?? "chip"}</span>+ ),+}));++function makeAdapter(+ overrides: Partial<NavigationAdapter> = {},+): NavigationAdapter {+ return {+ push: vi.fn(),+ replace: vi.fn(),+ back: vi.fn(),+ pathname: "/",+ searchParams: new URLSearchParams(),+ getShareableUrl: (p) => p,+ ...overrides,+ };+}++function renderCard(adapter: NavigationAdapter) {+ return render(+ <NavigationProvider value={adapter}>+ <IssueMentionCard issueId="issue-1" fallbackLabel="MUL-7" />+ </NavigationProvider>,+ );+}++describe("IssueMentionCard", () => {+ beforeEach(() => {+ issueLinkState.openInNewTab = true;+ });++ it("with the new-tab preference on (default), plain click opens a foreground new tab and does not push", () => {+ const push = vi.fn();+ const openInNewTab = vi.fn();+ renderCard(makeAdapter({ push, openInNewTab }));++ const anchor = screen.getByTestId("issue-chip").closest("a");+ expect(anchor).toHaveAttribute("target", "_blank");++ fireEvent.click(screen.getByTestId("issue-chip"));+ expect(openInNewTab).toHaveBeenCalledWith("/acme/issues/issue-1", "MUL-7", {+ activate: true,+ });+ expect(push).not.toHaveBeenCalled();+ });++ it("with the preference off, plain click navigates in place", () => {+ issueLinkState.openInNewTab = false;+ const push = vi.fn();+ const openInNewTab = vi.fn();+ renderCard(makeAdapter({ push, openInNewTab }));++ const anchor = screen.getByTestId("issue-chip").closest("a");+ expect(anchor).not.toHaveAttribute("target");++ fireEvent.click(screen.getByTestId("issue-chip"));+ expect(push).toHaveBeenCalledWith("/acme/issues/issue-1");+ expect(openInNewTab).not.toHaveBeenCalled();+ });++ it("with the preference on but no adapter openInNewTab (web), leaves the click to the browser's native target=_blank handling", () => {+ const push = vi.fn();+ renderCard(makeAdapter({ push }));++ const defaultNotPrevented = fireEvent.click(+ screen.getByTestId("issue-chip"),+ );+ expect(defaultNotPrevented).toBe(true);+ expect(push).not.toHaveBeenCalled();+ });+});diff --git a/packages/views/issues/components/issue-mention-card.tsx b/packages/views/issues/components/issue-mention-card.tsxindex 373a5e3012..ff26729b54 100644--- a/packages/views/issues/components/issue-mention-card.tsx+++ b/packages/views/issues/components/issue-mention-card.tsx@@ -2,6 +2,7 @@import { AppLink } from "../../navigation";import { useWorkspacePaths } from "@multica/core/paths";+import { useIssueLinkStore } from "@multica/core/issues/stores";import { IssueChip } from "./issue-chip";interface IssueMentionCardProps {@@ -14,11 +15,20 @@ interface IssueMentionCardProps {* Navigable chip — wraps IssueChip in an AppLink pointing at the issue's* detail page. Hover/cursor affordance is layered onto the chip itself so* the visual target matches the clickable target.+ *+ * Plain click honors the "open issue links in new tab" preference+ * (Settings → Preferences): new browser tab on web, new app tab on desktop.*/export function IssueMentionCard({ issueId, fallbackLabel }: IssueMentionCardProps) {const p = useWorkspacePaths();+ const openInNewTab = useIssueLinkStore((s) => s.openInNewTab);return (- <AppLink href={p.issueDetail(issueId)} className="issue-mention not-prose align-middle">+ <AppLink+ href={p.issueDetail(issueId)}+ target={openInNewTab ? "_blank" : undefined}+ newTabTitle={fallbackLabel}+ className="issue-mention not-prose align-middle"+ ><IssueChipissueId={issueId}fallbackLabel={fallbackLabel}diff --git a/packages/views/locales/en/settings.json b/packages/views/locales/en/settings.jsonindex 2a39b7b94b..69b5082be0 100644--- a/packages/views/locales/en/settings.json+++ b/packages/views/locales/en/settings.json@@ -30,6 +30,10 @@"sticky_comment_bar": {"title": "Sticky comment bar","hint": "Keep the comment bar pinned to the bottom while scrolling an issue page."+ },+ "issue_link_new_tab": {+ "title": "Open issue links in new tab",+ "hint": "Issue links in descriptions, comments, and chat open in a new tab instead of navigating in place."}},"shortcuts": {diff --git a/packages/views/locales/ja/settings.json b/packages/views/locales/ja/settings.jsonindex 452c917893..59ccffa469 100644--- a/packages/views/locales/ja/settings.json+++ b/packages/views/locales/ja/settings.json@@ -30,6 +30,10 @@"sticky_comment_bar": {"title": "コメントバーを固定","hint": "イシューのページをスクロールしても、コメントバーを常に下部に固定します。"+ },+ "issue_link_new_tab": {+ "title": "イシューリンクを新しいタブで開く",+ "hint": "説明・コメント・チャット内のイシューリンクを、その場で移動せず新しいタブで開きます。"}},"shortcuts": {diff --git a/packages/views/locales/ko/settings.json b/packages/views/locales/ko/settings.jsonindex ca4e3c2be4..df4187a20b 100644--- a/packages/views/locales/ko/settings.json+++ b/packages/views/locales/ko/settings.json@@ -30,6 +30,10 @@"sticky_comment_bar": {"title": "댓글 입력창 고정","hint": "이슈 페이지를 스크롤할 때 댓글 입력창을 항상 하단에 고정합니다."+ },+ "issue_link_new_tab": {+ "title": "이슈 링크를 새 탭에서 열기",+ "hint": "설명, 댓글, 채팅의 이슈 링크를 현재 페이지에서 이동하지 않고 새 탭에서 엽니다."}},"shortcuts": {diff --git a/packages/views/locales/zh-Hans/settings.json b/packages/views/locales/zh-Hans/settings.jsonindex f4e7ec2b21..89092c213b 100644--- a/packages/views/locales/zh-Hans/settings.json+++ b/packages/views/locales/zh-Hans/settings.json@@ -30,6 +30,10 @@"sticky_comment_bar": {"title": "固定评论栏","hint": "滚动 issue 页面时,评论栏始终固定在底部。"+ },+ "issue_link_new_tab": {+ "title": "在新标签页打开 issue 链接",+ "hint": "点击描述、评论或聊天中的 issue 链接时,在新标签页中打开,而不是在当前页面跳转。"}},"shortcuts": {diff --git a/packages/views/navigation/app-link.test.tsx b/packages/views/navigation/app-link.test.tsxindex 230b0c63e2..a6d36a521f 100644--- a/packages/views/navigation/app-link.test.tsx+++ b/packages/views/navigation/app-link.test.tsx@@ -86,10 +86,78 @@ describe("AppLink", () => {renderLink(adapter);fireEvent.click(screen.getByText("go"), { metaKey: true });- expect(openInNewTab).toHaveBeenCalledWith("/issues");+ expect(openInNewTab).toHaveBeenCalledWith("/issues", undefined);expect(push).not.toHaveBeenCalled();});+ it("modifier-click passes newTabTitle through as the tab label", () => {+ const openInNewTab = vi.fn();+ const adapter = makeAdapter({ openInNewTab });++ renderLink(adapter, { href: "/issues", newTabTitle: "MUL-7" });+ fireEvent.click(screen.getByText("go"), { metaKey: true });+ expect(openInNewTab).toHaveBeenCalledWith("/issues", "MUL-7");+ });++ describe("target=_blank (open-in-new-tab links)", () => {+ it("plain click opens a foreground new tab via the adapter (desktop) and does NOT push", () => {+ const push = vi.fn();+ const openInNewTab = vi.fn();+ const adapter = makeAdapter({ push, openInNewTab });++ renderLink(adapter, {+ href: "/issues",+ target: "_blank",+ newTabTitle: "MUL-7",+ });+ fireEvent.click(screen.getByText("go"));+ expect(openInNewTab).toHaveBeenCalledWith("/issues", "MUL-7", {+ activate: true,+ });+ expect(push).not.toHaveBeenCalled();+ });++ it("plain click without an adapter (web) neither pushes nor prevents default, so the browser's native target=_blank handling runs", () => {+ const push = vi.fn();+ const adapter = makeAdapter({ push });++ renderLink(adapter, { href: "/issues", target: "_blank" });+ // fireEvent returns false when preventDefault was called.+ const defaultNotPrevented = fireEvent.click(screen.getByText("go"));+ expect(defaultNotPrevented).toBe(true);+ expect(push).not.toHaveBeenCalled();+ });++ it("caller onClick still runs before the new-tab open", () => {+ const order: string[] = [];+ const adapter = makeAdapter({+ openInNewTab: vi.fn(() => order.push("openInNewTab")),+ });++ renderLink(adapter, {+ href: "/issues",+ target: "_blank",+ onClick: () => order.push("onClick"),+ });+ fireEvent.click(screen.getByText("go"));+ expect(order).toEqual(["onClick", "openInNewTab"]);+ });++ it("renders the target and a rel guard on the anchor", () => {+ renderLink(makeAdapter(), { href: "/issues", target: "_blank" });+ const anchor = screen.getByText("go");+ expect(anchor).toHaveAttribute("target", "_blank");+ expect(anchor).toHaveAttribute("rel", "noopener noreferrer");+ });++ it("renders no target or rel when target is not set", () => {+ renderLink(makeAdapter());+ const anchor = screen.getByText("go");+ expect(anchor).not.toHaveAttribute("target");+ expect(anchor).not.toHaveAttribute("rel");+ });+ });+it("a caller-supplied onClick passed via spread cannot silently override the navigation handler", () => {const push = vi.fn();const adapter = makeAdapter({ push });diff --git a/packages/views/navigation/app-link.tsx b/packages/views/navigation/app-link.tsxindex 743252bda5..c5457ae89b 100644--- a/packages/views/navigation/app-link.tsx+++ b/packages/views/navigation/app-link.tsx@@ -5,11 +5,16 @@ import { useNavigation } from "./context";interface AppLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {href: string;+ /**+ * Desktop only: label for the tab created when the click opens a new tab+ * (modifier-click or `target="_blank"`). Falls back to the path.+ */+ newTabTitle?: string;}export const AppLink = forwardRef<HTMLAnchorElement, AppLinkProps>(function AppLink(- { href, children, onClick, onMouseEnter, onFocus, ...props },+ { href, children, onClick, onMouseEnter, onFocus, target, newTabTitle, ...props },ref,) {const { push, openInNewTab, prefetch } = useNavigation();@@ -18,10 +23,23 @@ export const AppLink = forwardRef<HTMLAnchorElement, AppLinkProps>(if (e.metaKey || e.ctrlKey || e.shiftKey) {if (openInNewTab) {e.preventDefault();- openInNewTab(href);+ openInNewTab(href, newTabTitle);}return;}+ if (target === "_blank") {+ // Caller's onClick runs first — same contract as the push path below.+ onClick?.(e);+ if (openInNewTab) {+ // Desktop: foreground app tab. target="_blank" carries "take me+ // there" intent, matching the browser's foreground-tab behavior.+ e.preventDefault();+ openInNewTab(href, newTabTitle, { activate: true });+ }+ // Web: no adapter — leave the event alone so the browser's native+ // target="_blank" handling opens a real browser tab.+ return;+ }e.preventDefault();// Caller's onClick runs BEFORE push so any synchronous side effect// (close popover, clear selection, blur the trigger) lands in the@@ -44,6 +62,10 @@ export const AppLink = forwardRef<HTMLAnchorElement, AppLinkProps>(<aref={ref}href={href}+ target={target}+ // Referrer is same-origin noise here and noopener hygiene applies+ // even though the destination is our own app.+ rel={target === "_blank" ? "noopener noreferrer" : undefined}// Spread props first so that the navigation handlers below cannot be// silently overridden by a caller passing onClick/onMouseEnter/onFocus// through {...rest}. AppLink owns these three events.diff --git a/packages/views/settings/components/preferences-tab.tsx b/packages/views/settings/components/preferences-tab.tsxindex 27f3465256..e250dc09a3 100644--- a/packages/views/settings/components/preferences-tab.tsx+++ b/packages/views/settings/components/preferences-tab.tsx@@ -18,7 +18,10 @@ import {} from "@multica/core/i18n";import { useLocaleAdapter } from "@multica/core/i18n/react";import { useAuthStore } from "@multica/core/auth";-import { useCommentComposerStore } from "@multica/core/issues/stores";+import {+ useCommentComposerStore,+ useIssueLinkStore,+} from "@multica/core/issues/stores";import { api } from "@multica/core/api";import { browserTimezone, timezoneOptions } from "../../common/timezone-select";import { useT } from "../../i18n";@@ -163,6 +166,8 @@ export function PreferencesTab() {<TimezoneRow /><StickyCommentBarRow />++ <IssueLinkNewTabRow /></SettingsCard></SettingsSection></SettingsTab>@@ -193,6 +198,30 @@ function StickyCommentBarRow() {);}+function IssueLinkNewTabRow() {+ const { t } = useT("settings");+ const openInNewTab = useIssueLinkStore((s) => s.openInNewTab);+ const setOpenInNewTab = useIssueLinkStore((s) => s.setOpenInNewTab);++ return (+ <SettingsRow+ label={t(($) => $.preferences.issue_link_new_tab.title)}+ description={t(($) => $.preferences.issue_link_new_tab.hint)}+ >+ <Switch+ checked={openInNewTab}+ onCheckedChange={(checked) => {+ setOpenInNewTab(checked === true);+ toast.success(t(($) => $.auto_save.toast_saved), {+ id: "settings-auto-save",+ });+ }}+ aria-label={t(($) => $.preferences.issue_link_new_tab.title)}+ />+ </SettingsRow>+ );+}+// Base UI rejects "" as a SelectItem value, so route the "no preference"// state through this sentinel and translate at the wire boundary.const BROWSER_TZ_VALUE = "__browser__";