fix: Middle click read-only doc link in FF opens duplicate tabs (#10122)

closes #10083
This commit is contained in:
Tom Moor
2025-09-07 22:06:31 +02:00
committed by GitHub
parent 5337770adb
commit ec0e7aaba4
3 changed files with 15 additions and 1 deletions

View File

@@ -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");
}
},

View File

@@ -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;
}

View File

@@ -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 {