Skip to content

Commit e58ed36

Browse files
authored
breaking(Transition): Only call findDOMNode if necessary (#2)
Cherry-picking reactjs#468 ## Breaking Callbacks that use argument spread or access `arguments` will not have acces to the DOM node. The DOM node is only passed if Function.prototype.length is greater than 0. ``` // no node passed const noNodeCallback = () => {}; // node passed const withNodeCallback = node => {}; ``` The first callback enables strict mode compatible usage of `Transition`. If you expect the node in callbacks a call to `findDOMNode` is required which issues a warning in `React.StrictMode`.
1 parent 8decc30 commit e58ed36

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Transition.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class Transition extends React.Component {
208208
if (nextStatus !== null) {
209209
// nextStatus will always be ENTERING or EXITING.
210210
this.cancelNextCallback()
211-
const node = ReactDOM.findDOMNode(this)
211+
const node = this.needsNode() ? ReactDOM.findDOMNode(this) : null;
212212

213213
if (nextStatus === ENTERING) {
214214
this.performEnter(node, mounting)
@@ -312,7 +312,7 @@ class Transition extends React.Component {
312312
this.setNextCallback(handler)
313313

314314
const doesNotHaveTimeoutOrListener = timeout == null && !this.props.addEndListener
315-
if (!node || doesNotHaveTimeoutOrListener) {
315+
if (doesNotHaveTimeoutOrListener) {
316316
setTimeout(this.nextCallback, 0)
317317
return
318318
}
@@ -326,6 +326,19 @@ class Transition extends React.Component {
326326
}
327327
}
328328

329+
needsNode() {
330+
return [
331+
'addEndListener',
332+
'onEnter',
333+
'onEntering',
334+
'onEntered',
335+
'onExit'
336+
].some(callbackName => {
337+
const callback = this.props[callbackName];
338+
return callback && callback.length > 0
339+
})
340+
}
341+
329342
render() {
330343
const status = this.state.status
331344
if (status === UNMOUNTED) {

0 commit comments

Comments
 (0)