From e82815e1d684fc58d20fa7e384d736fbe2b6c38a Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 4 Jan 2024 17:48:14 -0500 Subject: [PATCH] fix: Link to share link in document should be treated as external. closes #6347 --- app/hooks/useEditorClickHandlers.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/hooks/useEditorClickHandlers.ts b/app/hooks/useEditorClickHandlers.ts index 822a2e9e8..5c8f82a9d 100644 --- a/app/hooks/useEditorClickHandlers.ts +++ b/app/hooks/useEditorClickHandlers.ts @@ -5,11 +5,12 @@ import { isModKey } from "~/utils/keyboard"; import { sharedDocumentPath } from "~/utils/routeHelpers"; import { isHash } from "~/utils/urls"; -export default function useEditorClickHandlers({ - shareId, -}: { +type Params = { + /** The share ID of the document being viewed, if any */ shareId?: string; -}) { +}; + +export default function useEditorClickHandlers({ shareId }: Params) { const history = useHistory(); const handleClickLink = React.useCallback( (href: string, event: MouseEvent) => { @@ -39,6 +40,12 @@ export default function useEditorClickHandlers({ return; } + // If we're navigating to a share link from a non-share link then open it in a new tab + if (shareId && navigateTo.startsWith("/s/")) { + window.open(href, "_blank"); + return; + } + // If we're navigating to an internal document link then prepend the // share route to the URL so that the document is loaded in context if (shareId && navigateTo.includes("/doc/")) {