From 5d325495a9c30c5a9d89fc2adfa620b8fde9346e Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Fri, 24 May 2024 17:12:15 +0100 Subject: [PATCH] fix: Profile page crash due to invalid topLevelElement (#15198) --- .../ui/components/editor/plugins/ToolbarPlugin.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/ui/components/editor/plugins/ToolbarPlugin.tsx b/packages/ui/components/editor/plugins/ToolbarPlugin.tsx index 5b30d90a7a0b5c..9e3a07036eb217 100644 --- a/packages/ui/components/editor/plugins/ToolbarPlugin.tsx +++ b/packages/ui/components/editor/plugins/ToolbarPlugin.tsx @@ -371,7 +371,15 @@ export default function ToolbarPlugin(props: TextEditorProps) { const nodes = $generateNodesFromDOM(editor, dom); $getRoot().select(); - $insertNodes(nodes); + try { + $insertNodes(nodes); + } catch (e: unknown) { + // resolves: "topLevelElement is root node at RangeSelection.insertNodes" + // @see https://stackoverflow.com/questions/73094258/setting-editor-from-html + const paragraphNode = $createParagraphNode(); + nodes.forEach((n) => paragraphNode.append(n)); + $getRoot().append(paragraphNode); + } editor.registerUpdateListener(({ editorState, prevEditorState }) => { editorState.read(() => {