diff --git a/packages/ui/components/editor/Editor.test.tsx b/packages/ui/components/editor/Editor.test.tsx index f3ca4629d0..f7b0f776ea 100644 --- a/packages/ui/components/editor/Editor.test.tsx +++ b/packages/ui/components/editor/Editor.test.tsx @@ -7,7 +7,7 @@ import type { TextEditorProps } from "./types"; describe("Editor", () => { const defaultProps: TextEditorProps = { - getText: vi.fn(), + getText: vi.fn(() => ""), setText: vi.fn(), variables: ["name", "email"], height: "200px", diff --git a/packages/ui/components/editor/plugins/ToolbarPlugin.tsx b/packages/ui/components/editor/plugins/ToolbarPlugin.tsx index ca62a447bf..01fec94b28 100644 --- a/packages/ui/components/editor/plugins/ToolbarPlugin.tsx +++ b/packages/ui/components/editor/plugins/ToolbarPlugin.tsx @@ -220,6 +220,7 @@ function getSelectedNode(selection: RangeSelection) { } export default function ToolbarPlugin(props: TextEditorProps) { + const isInitialized = useRef(false); const [editor] = useLexicalComposerContext(); const toolbarRef = useRef(null); const [blockType, setBlockType] = useState("paragraph"); @@ -364,11 +365,13 @@ export default function ToolbarPlugin(props: TextEditorProps) { }, [props.updateTemplate]); useEffect(() => { - if (props.setFirstRender) { + if (props.setFirstRender && !isInitialized.current) { + isInitialized.current = true; props.setFirstRender(false); editor.update(() => { const parser = new DOMParser(); - const dom = parser.parseFromString(props.getText(), "text/html"); + const content = props.getText()?.replace(/\n/g, "
"); + const dom = parser.parseFromString(content, "text/html"); const nodes = $generateNodesFromDOM(editor, dom);