From 46d745cb60c3ca6e59fb3ff4dbd4fbc743a20dcc Mon Sep 17 00:00:00 2001 From: Jiang Bohan Date: Tue, 14 Apr 2026 15:47:52 +0800 Subject: [PATCH] fix(editor): avoid accessing editor.view during initial render in link preview EditorLinkPreview's useRef initializer accessed editor.view?.dom which throws when the editor view is not yet mounted (Tiptap uses a Proxy that rejects property access before mount). Defer the contextElement assignment to the selectionUpdate callback where the view is guaranteed to exist. --- packages/views/editor/link-preview.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/views/editor/link-preview.tsx b/packages/views/editor/link-preview.tsx index be41cfa46..729f44a72 100644 --- a/packages/views/editor/link-preview.tsx +++ b/packages/views/editor/link-preview.tsx @@ -156,9 +156,10 @@ function EditorLinkPreview({ editor }: { editor: Editor }) { const close = useCallback(() => setVisible(false), []); + // Avoid accessing editor.view during initial render — it may not be mounted yet. const virtualRef = useRef({ getBoundingClientRect: () => new DOMRect(), - contextElement: editor.view?.dom, + contextElement: undefined as Element | undefined, }); const { refs, floatingStyles, isPositioned, update } = useFloating({