From aef5a083f935ed848050d0d178b46970b8602a6a Mon Sep 17 00:00:00 2001 From: Adeel Ahmad Date: Sun, 4 Oct 2026 11:53:40 +0000 Subject: [PATCH] fix(notes): keep typing when a thing's page is first saved, and open only web links The editor and form were keyed on the page id, so the first save of a recording's or entity's page remounted them and lost what was typed meanwhile. Key on what the page is about instead. BlockSuite renders any href from the Markdown, so links other than http(s), mailto and Lens links no longer open. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01XZQXJtCvJgbG1Z2H312KcS --- nextjs-frontend/components/notes/block-editor.tsx | 13 +++++++++---- nextjs-frontend/components/notes/note-page.tsx | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/nextjs-frontend/components/notes/block-editor.tsx b/nextjs-frontend/components/notes/block-editor.tsx index 8f4e312bc..db313d93f 100644 --- a/nextjs-frontend/components/notes/block-editor.tsx +++ b/nextjs-frontend/components/notes/block-editor.tsx @@ -24,6 +24,7 @@ type Props = { }; const LENS_LINK = /^(recording|entity|collection|speaker|page):\d+$/; +const WEB_LINK = /^(https?:|mailto:)/i; function toBase64(bytes: Uint8Array): string { let s = ""; @@ -144,16 +145,19 @@ export default function BlockEditor({ markdown, doc, readOnly, onChange, search, editor.mode = "page"; host.current.replaceChildren(editor); - // Links to things in Lens open in the app, not as web addresses. + // Links to things in Lens open in the app, not as web addresses. Other links open only as web or mail addresses: + // BlockSuite renders any href it is given, and the Markdown may come from the assistant (`javascript:` and such). const onClick = (e: MouseEvent) => { const a = (e.composedPath().find((n) => n instanceof HTMLAnchorElement) ?? null) as HTMLAnchorElement | null; - const href = a?.getAttribute("href") ?? ""; - if (!LENS_LINK.test(href)) return; + if (!a) return; + const href = (a.getAttribute("href") ?? "").trim(); + if (WEB_LINK.test(href)) return; e.preventDefault(); e.stopPropagation(); - latest.current.onOpenLink(href); + if (e.type === "click" && LENS_LINK.test(href)) latest.current.onOpenLink(href); }; host.current.addEventListener("click", onClick, true); + host.current.addEventListener("auxclick", onClick, true); let timer: ReturnType | undefined; const save = async (flush = false) => { @@ -183,6 +187,7 @@ export default function BlockEditor({ markdown, doc, readOnly, onChange, search, clearTimeout(timer); changed.dispose(); el.removeEventListener("click", onClick, true); + el.removeEventListener("auxclick", onClick, true); el.replaceChildren(); collection.dispose(); }; diff --git a/nextjs-frontend/components/notes/note-page.tsx b/nextjs-frontend/components/notes/note-page.tsx index 486d8a82f..d05b5d06a 100644 --- a/nextjs-frontend/components/notes/note-page.tsx +++ b/nextjs-frontend/components/notes/note-page.tsx @@ -51,7 +51,7 @@ export function NotePage({ id, about }: { id?: number; about?: string }) { const loadedFor = useRef(null); useEffect(() => { if (!page) return; - const k = `${page.id ?? "draft"}:${page.about ?? ""}`; + const k = page.about ?? `page:${page.id}`; if (loadedFor.current === k) return; loadedFor.current = k; setTitle(page.title); @@ -263,7 +263,7 @@ export function NotePage({ id, about }: { id?: number; about?: string }) { {saved?.updated_at && Changed {shortDate(saved.updated_at)}}