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.
This commit is contained in:
Jiang Bohan
2026-04-14 15:47:52 +08:00
parent 0a998d1cef
commit 46d745cb60

View File

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