diff --git a/.changeset/popular-shrimps-give.md b/.changeset/popular-shrimps-give.md new file mode 100644 index 000000000..1d50b95d0 --- /dev/null +++ b/.changeset/popular-shrimps-give.md @@ -0,0 +1,5 @@ +--- +'slate-react': minor +--- + +Fixed occasional crashes when selecting void elements in Chrome diff --git a/packages/slate-react/src/plugin/react-editor.ts b/packages/slate-react/src/plugin/react-editor.ts index d5d72ca5e..15281ab64 100644 --- a/packages/slate-react/src/plugin/react-editor.ts +++ b/packages/slate-react/src/plugin/react-editor.ts @@ -869,7 +869,8 @@ export const ReactEditor: ReactEditorInterface = { // will cause `toSlatePoint` to throw an error. (2023/03/07) if ( 'getAttribute' in focusNode && - (focusNode as HTMLElement).getAttribute('contenteditable') === 'false' + (focusNode as HTMLElement).getAttribute('contenteditable') === 'false' && + (focusNode as HTMLElement).getAttribute('data-slate-void') !== 'true' ) { focusNode = anchorNode focusOffset = anchorNode.textContent?.length || 0