fix: supplement of (fix: Prevent ReactEditor.toDOMRange crash in setDomSelection #5741) #5792
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.
Sorry, ue to the problem of English writing ability, the following English content is translated from Chinese by claude3.5
Description
任何会改变 selection 的 op 同步到 dom 之前,onDOMSelectionChange 都不应该执行
onDOMSelectionChange should not be executed before any selection-changing operations are synchronized to the DOM
Issue
所有出现”Cannot resolve a DOM point from Slate point“的 issue 可能都是,包括但不限于:
Maybe all issues where 'Cannot resolve a DOM point from Slate point' occurs include but are not limited to:
Fixes: (link to issue)
#5694
Example
This is common in collaborative scenarios. For example, with content '1234567' and cursor at the end:
These are the ideal steps, but the issue occurs between steps 2 and 3, where onDOMSelectionChange might execute (timing is uncertain due to throttle).
onDOMSelectionChange performs the following:
Line 279: Transforms.select(editor, range)
Before this, editor.selection changed from [0,0], 7 to [0,0], 6, but hasn't been synchronized to domSelection yet.
However, onDOMSelectionChange reads the old domSelection before synchronization and syncs it back to editor.selection, changing [0,0], 6 back to [0,0], 7.
After the operation to delete '7' is rendered to DOM, useIsomorphicLayoutEffect will synchronize editor.selection & domSelection again.
At this point, '7' no longer exists in the page DOM, leading to "Cannot resolve a DOM point from Slate point: {path: [0,0], offset: 7}"
Context
thanks to
Commit e97a9f8
Checks
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)