From 84aea058f367091babe2bf937863c966739eadba Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Mon, 7 Sep 2026 05:03:28 +0100 Subject: [PATCH] fix(editor): guard unresolved page mentions and bare anchor links A page mention without a slug rendered as a link ending in -null; it now renders as plain text. A link whose href is a bare #fragment scrolls to the target on the current page instead of opening about:blank. --- .../editor/components/link/link-view.tsx | 10 +++++++++ .../components/mention/mention-view.tsx | 22 ++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/apps/client/src/features/editor/components/link/link-view.tsx b/apps/client/src/features/editor/components/link/link-view.tsx index daa5bb5de..35f2bf562 100644 --- a/apps/client/src/features/editor/components/link/link-view.tsx +++ b/apps/client/src/features/editor/components/link/link-view.tsx @@ -224,6 +224,16 @@ export default function LinkView(props: MarkViewProps) { const handleNavigate = useCallback(() => { if (!href) return; + if (href.startsWith("#")) { + const anchor = href.slice(1); + const element = + document.querySelector(`[id="${anchor}"]`) || + document.querySelector(`[data-id="${anchor}"]`); + element?.scrollIntoView({ behavior: "smooth", block: "start" }); + navigate(`${location.pathname}#${anchor}`, { replace: true }); + return; + } + if (isInternal) { let targetPath = href; let anchor = ""; diff --git a/apps/client/src/features/editor/components/mention/mention-view.tsx b/apps/client/src/features/editor/components/mention/mention-view.tsx index 561f3e0f8..521593f22 100644 --- a/apps/client/src/features/editor/components/mention/mention-view.tsx +++ b/apps/client/src/features/editor/components/mention/mention-view.tsx @@ -15,6 +15,7 @@ export default function MentionView(props: NodeViewProps) { const { node } = props; const { label, entityType, entityId, slugId, anchorId } = node.attrs; const isPageMention = entityType === "page"; + const hasTarget = isPageMention && !!slugId; const { spaceSlug, pageSlug } = useParams(); const { shareId } = useParams(); const navigate = useNavigate(); @@ -63,7 +64,22 @@ export default function MentionView(props: NodeViewProps) { )} - {isPageMention && isShareRoute && ( + {isPageMention && !hasTarget && ( + + + + + {label} + + )} + + {hasTarget && isShareRoute && ( )} - {isPageMention && !isShareRoute && isError && ( + {hasTarget && !isShareRoute && isError && ( )} - {isPageMention && !isShareRoute && !isError && ( + {hasTarget && !isShareRoute && !isError && (