From 0585b68fed5e1d732692f24989fa0fb1dd54c6f2 Mon Sep 17 00:00:00 2001 From: Kevin Chavez Date: Wed, 22 Apr 2020 13:05:50 -0700 Subject: [PATCH] Short-circuit getUpdatedSelectionState for invalid selection updates on prod MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: The code already did this for __DEV__, but it was misswritten, since instead of skipping the wanring on prod, it skipped the whole check. This essentially deals with empty-string keys, which mean nothing. This wasn't much of an issue— we'd simply not get any leafs and exit on a following check. Reviewed By: claudiopro Differential Revision: D21145150 fbshipit-source-id: bb78aa076d98f5d642a2ae8eb13c158dde8a76e3 --- src/component/selection/getUpdatedSelectionState.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/component/selection/getUpdatedSelectionState.js b/src/component/selection/getUpdatedSelectionState.js index 0db774f3c1..7ebd6c69cc 100644 --- a/src/component/selection/getUpdatedSelectionState.js +++ b/src/component/selection/getUpdatedSelectionState.js @@ -26,12 +26,13 @@ function getUpdatedSelectionState( focusOffset: number, ): SelectionState { const selection: SelectionState = nullthrows(editorState.getSelection()); - if (__DEV__) { - if (!anchorKey || !focusKey) { + if (!anchorKey || !focusKey) { + // If we cannot make sense of the updated selection state, stick to the current one. + if (__DEV__) { /* eslint-disable-next-line */ console.warn('Invalid selection state.', arguments, editorState.toJS()); - return selection; } + return selection; } const anchorPath = DraftOffsetKey.decode(anchorKey);