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

Support React v16 when editor is focused after removed from DOM #1409

Closed
wants to merge 4 commits into from
Closed
Changes from 3 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
6 changes: 6 additions & 0 deletions src/component/base/DraftEditor.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ class DraftEditor extends React.Component<DraftEditorProps, State> {
const alreadyHasFocus = editorState.getSelection().getHasFocus();
const editorNode = ReactDOM.findDOMNode(this.refs.editor);

if (!editorNode) {
// once in a while people call 'focus' in a setTimeout, and the node has
// been deleted, so it can be null in that case.
return;
}

const scrollParent = Style.getScrollParent(editorNode);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct me if I'm wrong, but Style.getScrollParent has 1 param & that is node, so we don't want to call it unless we have an HTMLElement, right? It doesn't matter either way (code below), but if we were writing a unit test for this, then it'd be REALLY hard to reach that invariant...

getScrollParent: function getScrollParent(node) {
	    if (!node) {
	      return null;
	    }
            ...

const {x, y} = scrollPosition || getScrollPosition(scrollParent);

Expand Down