Skip to content

Commit 4c1e525

Browse files
authored
fix: custom inline content crash (#788)
1 parent 624f4b1 commit 4c1e525

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

packages/react/src/schema/@util/ReactRenderUtil.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@ export function renderToDOMSpec(
1010
const div = document.createElement("div");
1111

1212
let root: Root | undefined;
13-
if (!editor) {
14-
// If no editor is provided, use a temporary root.
13+
const { _tiptapEditor } = editor || {};
14+
15+
if (_tiptapEditor?.contentComponent) {
16+
// Render temporarily using `EditorContent` (which is stored somewhat hacky on `_tiptapEditor.contentComponent`)
17+
// This way React Context will still work, as `fc` will be rendered inside the existing React tree
18+
_tiptapEditor.contentComponent.renderToElement(
19+
fc((el) => (contentDOM = el || undefined)),
20+
div
21+
);
22+
} else {
23+
// If no editor is provided, or if _tiptapEditor or _tiptapEditor.contentComponent is undefined, use a temporary root.
1524
// This is currently only used for Styles. In this case, react context etc. won't be available inside `fc`
1625
root = createRoot(div);
1726
flushSync(() => {
1827
root!.render(fc((el) => (contentDOM = el || undefined)));
1928
});
20-
} else {
21-
// Render temporarily using `EditorContent` (which is stored somewhat hacky on `editor._tiptapEditor.contentComponent`)
22-
// This way React Context will still work, as `fc` will be rendered inside the existing React tree
23-
editor._tiptapEditor.contentComponent.renderToElement(
24-
fc((el) => (contentDOM = el || undefined)),
25-
div
26-
);
2729
}
2830

2931
if (!div.childElementCount) {

0 commit comments

Comments
 (0)