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

Commit

Permalink
Remove findDOMNode from DraftEditorBlockNode
Browse files Browse the repository at this point in the history
Summary:
This is part of DraftEditorContentsExperimental which is not actually rolled out anywhere.

It's only used on some test pages for specific users:

https://our.intern.facebook.com/intern/gatekeeper/projects/draft_tree_data_support/

I don't know if we have plans of actually rolling this out further. So I'll give it a benefit of a doubt that maybe we'll want to get back to it.

We have to 100% get rid of findDOMNode uses in React though and this is technically reachable from Comet if the GK turns on. So I have to fix it or remove it.

This diff fixes it by attaching a ref to the wrapper element created by blocks.

However, if this is rendered in a parent a wrapper is not created.

https://github.com/facebook/draft-js/blob/bafe30ab702c10b463fc7ee60bc2d6d9d4f7aef3/src/component/contents/exploration/DraftEditorBlockNode.react.js#L370

The non-experimental version uses a permanent wrapper div for this (D14716519):

https://github.com/facebook/draft-js/blob/dceddf552006ea607bc5c15ce3d1b629eca1cb70/src/component/contents/DraftEditorBlock.react.js#L241

However, I'm not sure how you can even create a nested custom block and if scrolling is even relevant in that case. So my fix disables the auto-scrolling in that edge case. Seems good enough to me given that nobody is currently using this. I defer to the Draft.js team for a more permanent fix if we're rolling this out further.

Reviewed By: gaearon

Differential Revision: D19564783

fbshipit-source-id: f8250133334824f130a4214999a4768f39d49f4b
  • Loading branch information
sebmarkbage authored and facebook-github-bot committed Jan 25, 2020
1 parent c1a55ce commit 0dd3978
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/component/contents/exploration/DraftEditorBlockNode.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import type {BidiDirection} from 'UnicodeBidiDirection';
const DraftEditorNode = require('DraftEditorNode.react');
const DraftOffsetKey = require('DraftOffsetKey');
const React = require('React');
const ReactDOM = require('ReactDOM');
const Scroll = require('Scroll');
const Style = require('Style');

Expand Down Expand Up @@ -177,12 +176,14 @@ const getElementPropsConfig = (
offsetKey: string,
blockStyleFn: BlockStyleFn,
customConfig: *,
ref: null | {|current: null | Element|},
): Object => {
let elementProps: Object = {
'data-block': true,
'data-editor': editorKey,
'data-offset-key': offsetKey,
key: block.getKey(),
ref,
};
const customClass = blockStyleFn(block);

Expand All @@ -202,6 +203,8 @@ const getElementPropsConfig = (
};

class DraftEditorBlockNode extends React.Component<Props> {
wrapperRef: {|current: null | Element|} = React.createRef<Element>();

shouldComponentUpdate(nextProps: Props): boolean {
const {block, direction, tree} = this.props;
const isContainerNode = !block.getChildKeys().isEmpty();
Expand Down Expand Up @@ -236,7 +239,11 @@ class DraftEditorBlockNode extends React.Component<Props> {
return;
}

const blockNode = ReactDOM.findDOMNode(this);
const blockNode = this.wrapperRef.current;
if (!blockNode) {
// This Block Node was rendered without a wrapper element.
return;
}
const scrollParent = Style.getScrollParent(blockNode);
const scrollPosition = getScrollPosition(scrollParent);
let scrollDelta;
Expand Down Expand Up @@ -303,6 +310,7 @@ class DraftEditorBlockNode extends React.Component<Props> {
offsetKey,
blockStyleFn,
customConfig,
null,
);
const childProps = {
...this.props,
Expand Down Expand Up @@ -377,6 +385,7 @@ class DraftEditorBlockNode extends React.Component<Props> {
offsetKey,
blockStyleFn,
customConfig,
this.wrapperRef,
);

// root block nodes needs to be wrapped
Expand Down

0 comments on commit 0dd3978

Please sign in to comment.