Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces two changes:
onInput
prop on the<Editable>
component, but it wasn't being invoked, which is now fixed.restore-dom-manager
no longer revertscharacterData
mutationsThese changes are introduced so that consumers can listen to the
onInput
event to flush pending diffs on Android on every change:Before this PR, it was not possible to reconcile the editor state on every input event, because of the
textContent
update when reverting thecharacterData
mutations. This would interrupt the current composition, and lead to unexpected results while typing quickly or holding backspace.Issue
Related: #5078
Examples
In isolation, this is what the change looks like:
Before
Screen.Recording.2023-02-22.at.7.34.14.PM.mov
After
Screen.Recording.2023-02-22.at.7.33.12.PM.mov
Here is a before/after of what this PR combined with #5306 unlocks:
Before
Screen.Recording.2023-02-22.at.8.03.33.PM.mov
After
Screen.Recording.2023-02-22.at.8.00.16.PM.mov
Playground
Compatibility
I have tested this PR extensively, but would appreciate help in validating that this does not introduce regressions.
So far, I have tested this PR against:
What's next
If we don't find any major regressions once this PR is merged, my recommendation would be to reconcile the editor state with the DOM on every input event by default, which is how the previous Android input manager used to work, and aligns with how Slate works on all other browsers.
It's imperative to keep the editor state in sync so that the other core parts of Slate, such as normalization, can function correctly.
This would also eliminate the need to handle Android differently when authoring plugins, such as how the current mentions example needs Android-specific logic to function properly on Android devices (see #5071 for example)
I haven't noticed any significant performance concerns with this approach on the devices I have been testing with, including real physical devices such as my mid-range 2021 Samsung Galaxy A32 running Android 11.
This would also allow removing the android-specific methods from the
ReactEditor
public API.Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)