From 420eef4d91d6c5810b4e9dbda1e87e9f0e6d8dba Mon Sep 17 00:00:00 2001 From: James Date: Thu, 15 Dec 2022 12:39:57 -0500 Subject: [PATCH] fix: safely handles rich text deselection --- src/admin/components/forms/field-types/RichText/RichText.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/admin/components/forms/field-types/RichText/RichText.tsx b/src/admin/components/forms/field-types/RichText/RichText.tsx index 4c18ea9e4c..2ba2a11390 100644 --- a/src/admin/components/forms/field-types/RichText/RichText.tsx +++ b/src/admin/components/forms/field-types/RichText/RichText.tsx @@ -206,9 +206,10 @@ const RichText: React.FC = (props) => { }, [loaded, readOnly]); useEffect(() => { + // If there is a change to the initial value, we need to reset Slate + // to the new initial value, and clear selection if (Array.isArray(initialValue) && initialValue.length > 0) { - const point = { path: [0, 0], offset: 0 }; - editor.selection = { anchor: point, focus: point }; + if (editor.selection) ReactEditor.deselect(editor); editor.history = { redos: [], undos: [] }; editor.children = initialValue; }