Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Updating selection between rendering can crash #1084

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meta/bundle-size-stats/Draft.js.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion meta/bundle-size-stats/Draft.min.js.json

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions src/component/selection/getUpdatedSelectionState.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,27 @@ function getUpdatedSelectionState(

const anchorPath = DraftOffsetKey.decode(anchorKey);
const anchorBlockKey = anchorPath.blockKey;
const anchorLeaf = editorState
.getBlockTree(anchorBlockKey)
.getIn([anchorPath.decoratorKey, 'leaves', anchorPath.leafKey]);
const anchorBlockTree = editorState.getBlockTree(anchorBlockKey);
if (!anchorBlockTree) {
return selection;
}
const anchorLeaf = anchorBlockTree.getIn([
anchorPath.decoratorKey,
'leaves',
anchorPath.leafKey,
]);

const focusPath = DraftOffsetKey.decode(focusKey);
const focusBlockKey = focusPath.blockKey;
const focusLeaf = editorState
.getBlockTree(focusBlockKey)
.getIn([focusPath.decoratorKey, 'leaves', focusPath.leafKey]);
const focusBlockTree = editorState.getBlockTree(focusBlockKey);
if (!focusBlockTree) {
return selection;
}
const focusLeaf = focusBlockTree.getIn([
focusPath.decoratorKey,
'leaves',
focusPath.leafKey,
]);

const anchorLeafStart: number = anchorLeaf.get('start');
const focusLeafStart: number = focusLeaf.get('start');
Expand Down