Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions packages/react/src/schema/@util/ReactRenderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ export function renderToDOMSpec(
const div = document.createElement("div");

let root: Root | undefined;
if (!editor) {
// If no editor is provided, use a temporary root.
const { _tiptapEditor } = editor || {};

if (_tiptapEditor?.contentComponent) {
// Render temporarily using `EditorContent` (which is stored somewhat hacky on `_tiptapEditor.contentComponent`)
// This way React Context will still work, as `fc` will be rendered inside the existing React tree
_tiptapEditor.contentComponent.renderToElement(
fc((el) => (contentDOM = el || undefined)),
div
);
} else {
// If no editor is provided, or if _tiptapEditor or _tiptapEditor.contentComponent is undefined, use a temporary root.
// This is currently only used for Styles. In this case, react context etc. won't be available inside `fc`
root = createRoot(div);
flushSync(() => {
root!.render(fc((el) => (contentDOM = el || undefined)));
});
} else {
// Render temporarily using `EditorContent` (which is stored somewhat hacky on `editor._tiptapEditor.contentComponent`)
// This way React Context will still work, as `fc` will be rendered inside the existing React tree
editor._tiptapEditor.contentComponent.renderToElement(
fc((el) => (contentDOM = el || undefined)),
div
);
}

if (!div.childElementCount) {
Expand Down