Skip to content

Commit 6fa2c8f

Browse files
authored
fix: useReactNodeView ref for React 19 compatibility (#1317)
1 parent a4b7f36 commit 6fa2c8f

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

packages/react/src/schema/ReactBlockSpec.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ import {
2121
} from "@blocknote/core";
2222
import {
2323
NodeView,
24-
NodeViewContent,
2524
NodeViewProps,
2625
NodeViewWrapper,
2726
ReactNodeViewRenderer,
27+
useReactNodeView,
2828
} from "@tiptap/react";
2929
import { FC, ReactNode } from "react";
3030
import { renderToDOMSpec } from "./@util/ReactRenderUtil.js";
@@ -168,8 +168,11 @@ export function createReactBlockSpec<
168168
const blockContentDOMAttributes =
169169
this.options.domAttributes?.blockContent || {};
170170

171-
// hacky, should export `useReactNodeView` from tiptap to get access to ref
172-
const ref = (NodeViewContent({}) as any).ref;
171+
const ref = useReactNodeView().nodeViewContentRef;
172+
173+
if (!ref) {
174+
throw new Error("nodeViewContentRef is not set");
175+
}
173176

174177
const BlockContent = blockImplementation.render;
175178
return (

packages/react/src/schema/ReactInlineContentSpec.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import {
1616
StyleSchema,
1717
} from "@blocknote/core";
1818
import {
19-
NodeViewContent,
2019
NodeViewProps,
2120
NodeViewWrapper,
2221
ReactNodeViewRenderer,
22+
useReactNodeView,
2323
} from "@tiptap/react";
2424
// import { useReactNodeView } from "@tiptap/react/dist/packages/react/src/useReactNodeView";
2525
import { FC } from "react";
@@ -149,8 +149,11 @@ export function createReactInlineContentSpec<
149149
return (props) =>
150150
ReactNodeViewRenderer(
151151
(props: NodeViewProps) => {
152-
// hacky, should export `useReactNodeView` from tiptap to get access to ref
153-
const ref = (NodeViewContent({}) as any).ref;
152+
const ref = useReactNodeView().nodeViewContentRef;
153+
154+
if (!ref) {
155+
throw new Error("nodeViewContentRef is not set");
156+
}
154157

155158
const Content = inlineContentImplementation.render;
156159
return (

0 commit comments

Comments
 (0)