From 4f8ef1742cadb93e656f9e03e543aa55b8c77226 Mon Sep 17 00:00:00 2001 From: yousefed Date: Wed, 11 Dec 2024 10:00:05 +0100 Subject: [PATCH] fix: useReactNodeView ref for React 19 compatibility --- packages/react/src/schema/ReactBlockSpec.tsx | 9 ++++++--- packages/react/src/schema/ReactInlineContentSpec.tsx | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/react/src/schema/ReactBlockSpec.tsx b/packages/react/src/schema/ReactBlockSpec.tsx index 03c75c7039..99b5e5f1cf 100644 --- a/packages/react/src/schema/ReactBlockSpec.tsx +++ b/packages/react/src/schema/ReactBlockSpec.tsx @@ -21,10 +21,10 @@ import { } from "@blocknote/core"; import { NodeView, - NodeViewContent, NodeViewProps, NodeViewWrapper, ReactNodeViewRenderer, + useReactNodeView, } from "@tiptap/react"; import { FC, ReactNode } from "react"; import { renderToDOMSpec } from "./@util/ReactRenderUtil.js"; @@ -168,8 +168,11 @@ export function createReactBlockSpec< const blockContentDOMAttributes = this.options.domAttributes?.blockContent || {}; - // hacky, should export `useReactNodeView` from tiptap to get access to ref - const ref = (NodeViewContent({}) as any).ref; + const ref = useReactNodeView().nodeViewContentRef; + + if (!ref) { + throw new Error("nodeViewContentRef is not set"); + } const BlockContent = blockImplementation.render; return ( diff --git a/packages/react/src/schema/ReactInlineContentSpec.tsx b/packages/react/src/schema/ReactInlineContentSpec.tsx index 0ab5ac0d70..0dfd2c7080 100644 --- a/packages/react/src/schema/ReactInlineContentSpec.tsx +++ b/packages/react/src/schema/ReactInlineContentSpec.tsx @@ -16,10 +16,10 @@ import { StyleSchema, } from "@blocknote/core"; import { - NodeViewContent, NodeViewProps, NodeViewWrapper, ReactNodeViewRenderer, + useReactNodeView, } from "@tiptap/react"; // import { useReactNodeView } from "@tiptap/react/dist/packages/react/src/useReactNodeView"; import { FC } from "react"; @@ -149,8 +149,11 @@ export function createReactInlineContentSpec< return (props) => ReactNodeViewRenderer( (props: NodeViewProps) => { - // hacky, should export `useReactNodeView` from tiptap to get access to ref - const ref = (NodeViewContent({}) as any).ref; + const ref = useReactNodeView().nodeViewContentRef; + + if (!ref) { + throw new Error("nodeViewContentRef is not set"); + } const Content = inlineContentImplementation.render; return (