From 747ebfda0a06b29fc31720f9172c67222fbeae07 Mon Sep 17 00:00:00 2001 From: Joe Anderson Date: Sat, 24 May 2025 21:53:27 +0100 Subject: [PATCH] Fix IME crash on iOS, but break capitalisation on iOS (#5877) * Revert "Make capitalizing work for iOS (#5654)" This reverts commit 2a8b4e958bd02f3b70da51c3880fd764270424ad. * Add changeset * Reference the older issue in comment --- .changeset/orange-ears-help.md | 5 +++++ packages/slate-react/src/components/string.tsx | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 .changeset/orange-ears-help.md diff --git a/.changeset/orange-ears-help.md b/.changeset/orange-ears-help.md new file mode 100644 index 000000000..79b6b6087 --- /dev/null +++ b/.changeset/orange-ears-help.md @@ -0,0 +1,5 @@ +--- +'slate-react': patch +--- + +Fix a crash on iOS when composing text using an IME at the start of a block, at the cost of breaking capitalization on iOS in an empty editor. diff --git a/packages/slate-react/src/components/string.tsx b/packages/slate-react/src/components/string.tsx index bdb069b72..5f1dce96b 100644 --- a/packages/slate-react/src/components/string.tsx +++ b/packages/slate-react/src/components/string.tsx @@ -3,7 +3,7 @@ import { Editor, Text, Path, Element, Node } from 'slate' import { ReactEditor, useSlateStatic } from '..' import { useIsomorphicLayoutEffect } from '../hooks/use-isomorphic-layout-effect' -import { IS_ANDROID, IS_IOS } from 'slate-dom' +import { IS_ANDROID } from 'slate-dom' import { MARK_PLACEHOLDER_SYMBOL } from 'slate-dom' /** @@ -127,9 +127,17 @@ export const ZeroWidthString = (props: { attributes['data-slate-mark-placeholder'] = true } + // FIXME: Inserting the \uFEFF on iOS breaks capitalization at the start of an + // empty editor (https://github.com/ianstormtaylor/slate/issues/5199). + // + // However, not inserting the \uFEFF on iOS causes the editor to crash when + // inserting any text using an IME at the start of a block. This appears to + // be because accepting an IME suggestion when at the start of a block (no + // preceding \uFEFF) removes one or more DOM elements that `toSlateRange` + // depends on. (https://github.com/ianstormtaylor/slate/issues/5703) return ( - {!(IS_ANDROID || IS_IOS) || !isLineBreak ? '\uFEFF' : null} + {!IS_ANDROID || !isLineBreak ? '\uFEFF' : null} {isLineBreak ?
: null}
)