Skip to content

Commit

Permalink
fix: #2272, rich text within blocks causing crash on reorder
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikrut committed Mar 9, 2023
1 parent ef826c8 commit 7daddf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/admin/components/forms/field-types/RichText/RichText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ const RichText: React.FC<Props> = (props) => {
CreatedEditor = enablePlugins(CreatedEditor, leaves);

return CreatedEditor;
}, [elements, leaves]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [elements, leaves, path]);

// All slate changes fire the onChange event
// including selection changes
Expand Down Expand Up @@ -225,6 +226,16 @@ const RichText: React.FC<Props> = (props) => {
};
}, [loaded, readOnly]);

// useEffect(() => {
// // If there is a change to the initial value, we need to reset Slate history
// // and clear selection because the old selection may no longer be valid
// // as returned JSON may be modified in hooks and have a different shape
// if (editor.selection) {
// console.log('deselecting');
// ReactEditor.deselect(editor);
// }
// }, [path, editor]);

if (!loaded) {
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion test/fields/collections/Blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export const blocksFieldSeedData = [
blockName: 'First block',
blockType: 'text',
text: 'first block',
richText: [],
richText: [{
children: [{ text: '' }],
}],
},
{
blockName: 'Second block',
Expand Down

0 comments on commit 7daddf8

Please sign in to comment.