Skip to content
This repository was archived by the owner on Dec 16, 2021. It is now read-only.

Commit ad59cf3

Browse files
tomascasasdevelopit
authored andcommitted
findDOMNode must return DOM Node or null (#431)
1 parent 6567dc1 commit ad59cf3

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ function shallowDiffers(a, b) {
395395

396396

397397
function findDOMNode(component) {
398-
return component && component.base || component;
398+
return component && component.base || null;
399399
}
400400

401401

test/index.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, {
33
createClass,
44
createElement,
55
cloneElement,
6+
findDOMNode,
67
Component,
78
PropTypes,
89
unstable_renderSubtreeIntoContainer,
@@ -284,6 +285,41 @@ describe('preact-compat', () => {
284285
});
285286
});
286287

288+
describe('findDOMNode()', () => {
289+
class Helper extends React.Component {
290+
render({something}) {
291+
if (something == null) return null;
292+
if (something === false) return null;
293+
return <div></div>;
294+
}
295+
}
296+
297+
it('should return DOM Node if render is not false nor null', () => {
298+
let scratch = document.createElement('div');
299+
(document.body || document.documentElement).appendChild(scratch);
300+
const helper = React.render(<Helper />, scratch);
301+
expect(findDOMNode(helper)).to.be.instanceof(Node);
302+
});
303+
304+
// NOTE: React.render() returning false or null has the component pointing
305+
// to no DOM Node, in contrast, Preact always render an empty Text DOM Node.
306+
xit('should return null if render returns false', () => {
307+
let scratch = document.createElement('div');
308+
(document.body || document.documentElement).appendChild(scratch);
309+
const helper = React.render(<Helper something={false} />, scratch);
310+
expect(findDOMNode(helper)).to.be.null;
311+
});
312+
313+
// NOTE: React.render() returning false or null has the component pointing
314+
// to no DOM Node, in contrast, Preact always render an empty Text DOM Node.
315+
xit('should return null if render returns null', () => {
316+
let scratch = document.createElement('div');
317+
(document.body || document.documentElement).appendChild(scratch);
318+
const helper = React.render(<Helper something={null} />, scratch);
319+
expect(findDOMNode(helper)).to.be.null;
320+
});
321+
});
322+
287323
describe('unstable_renderSubtreeIntoContainer', () => {
288324
class Inner extends Component {
289325
render() {

0 commit comments

Comments
 (0)