From ec0e7aaba481c8a4abb88b243592a2c4f1324a9a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sun, 7 Sep 2025 22:06:31 +0200 Subject: [PATCH] fix: Middle click read-only doc link in FF opens duplicate tabs (#10122) closes #10083 --- app/hooks/useEditorClickHandlers.ts | 7 +++++++ shared/editor/marks/Link.tsx | 2 +- shared/utils/browser.ts | 7 +++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/hooks/useEditorClickHandlers.ts b/app/hooks/useEditorClickHandlers.ts index 8d3437df86..5fefc61ac3 100644 --- a/app/hooks/useEditorClickHandlers.ts +++ b/app/hooks/useEditorClickHandlers.ts @@ -5,6 +5,7 @@ import { isDocumentUrl, isInternalUrl } from "@shared/utils/urls"; import { sharedModelPath } from "~/utils/routeHelpers"; import { isHash } from "~/utils/urls"; import useStores from "./useStores"; +import { isFirefox } from "@shared/utils/browser"; type Params = { /** The share ID of the document being viewed, if any */ @@ -78,6 +79,12 @@ export default function useEditorClickHandlers({ shareId }: Params) { window.open(navigateTo, "_blank"); } } else { + // Middle-click events in Firefox are not prevented in the same way as other browsers + // so we need to explicitly return here to prevent two tabs from being opened when + // middle-clicking a link (#10083). + if (event?.button === 1 && isFirefox()) { + return; + } window.open(href, "_blank"); } }, diff --git a/shared/editor/marks/Link.tsx b/shared/editor/marks/Link.tsx index ccb93eaec4..6e26fc57bf 100644 --- a/shared/editor/marks/Link.tsx +++ b/shared/editor/marks/Link.tsx @@ -230,7 +230,7 @@ export default class Link extends Mark { click: (_view: EditorView, event: MouseEvent) => { if ( !(event.target instanceof HTMLAnchorElement) || - event.button !== 0 + (event.button !== 0 && event.button !== 1) ) { return false; } diff --git a/shared/utils/browser.ts b/shared/utils/browser.ts index bdd6729af7..14cee6d8ae 100644 --- a/shared/utils/browser.ts +++ b/shared/utils/browser.ts @@ -91,6 +91,13 @@ export function isSafari(): boolean { ); } +export function isFirefox(): boolean { + if (!isBrowser) { + return false; + } + return window.navigator.userAgent.includes("Firefox"); +} + let supportsPassive = false; try {