Skip to content

Commit

Permalink
fix(*): resolve facebook/react#14188 for compat ablout findDOMNode
Browse files Browse the repository at this point in the history
  • Loading branch information
dengyongqing committed Feb 4, 2020
1 parent b14cbcd commit 8a69d9c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/overlay/gateway.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class Gateway extends Component {
}

componentWillReceiveProps(nextProps) {
this.containerNode = this.getContainerNode(nextProps);
this.containerNode = nextProps ? this.getContainerNode(nextProps) : null;
}

getContainerNode(props) {
Expand All @@ -32,7 +32,7 @@ export default class Gateway extends Component {
}

getChildNode() {
return findDOMNode(this.child);
return this.child ? findDOMNode(this.child) : null;
}

saveChildRef = ref => {
Expand Down
3 changes: 3 additions & 0 deletions src/overlay/overlay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ export default class Overlay extends Component {
}

getContentNode() {
if (!this.contentRef) {
return null;
}
return findDOMNode(this.contentRef);
}

Expand Down
9 changes: 7 additions & 2 deletions src/overlay/position.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,18 @@ export default class Position extends Component {
}

getContentNode() {
if (!this) {
return null;
}
return findDOMNode(this);
}

getTargetNode() {
const { target } = this.props;

return target === position.VIEWPORT
if (!target) {
return null;
}
return (target === position.VIEWPORT)
? position.VIEWPORT
: findNode(target, this.props);
}
Expand Down
2 changes: 1 addition & 1 deletion src/overlay/utils/find-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function findNode(target, param) {
}

if (typeof target === 'function') {
target = target(param);
target = param ? target(param) : null;
}

if (!target) {
Expand Down
12 changes: 10 additions & 2 deletions src/table/lock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,16 @@ export default function lock(BaseComponent) {
}
);

const node = findDOMNode(this);
const width = node.clientWidth;
let width = 0;
// 捕获findDOMNode异常情况
try {
const node = findDOMNode(this);
width = node.clientWidth;
} catch (e) {
console.error(error);
width = 0;
throw e;
}

// if the table doesn't exist, there is no need to adjust
if (width === 0) {
Expand Down

0 comments on commit 8a69d9c

Please sign in to comment.