Skip to content

Commit

Permalink
fix: Profile page crash due to invalid topLevelElement (#15198)
Browse files Browse the repository at this point in the history
  • Loading branch information
emrysal authored May 24, 2024
1 parent dead2b8 commit 5d32549
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/ui/components/editor/plugins/ToolbarPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit 5d32549

Please sign in to comment.