Skip to content

Commit

Permalink
Fix "Cannot read property 'classList' of null" when the child of CSST…
Browse files Browse the repository at this point in the history
…ransition is rendered as null (#208) (#270)
  • Loading branch information
luontola authored and jquense committed Jan 5, 2018
1 parent 153d562 commit 9cbb3e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/CSSTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import React from 'react';
import Transition from './Transition';
import { classNamesShape } from './utils/PropTypes';

const addClass = (node, classes) => classes && classes.split(' ').forEach(c => addOneClass(node, c));
const removeClass = (node, classes) => classes && classes.split(' ').forEach(c => removeOneClass(node, c));
const addClass = (node, classes) => node && classes && classes.split(' ').forEach(c => addOneClass(node, c));
const removeClass = (node, classes) => node && classes && classes.split(' ').forEach(c => removeOneClass(node, c));

const propTypes = {
...Transition.propTypes,
Expand Down Expand Up @@ -190,7 +190,7 @@ class CSSTransition extends React.Component {
// This is for to force a repaint,
// which is necessary in order to transition styles when adding a class name.
/* eslint-disable no-unused-expressions */
node.scrollTop;
node && node.scrollTop;
/* eslint-enable no-unused-expressions */
addClass(node, className);
}
Expand Down
22 changes: 22 additions & 0 deletions test/CSSTransitionGroup-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,28 @@ describe('CSSTransitionGroup', () => {
);
});

it('should work with a child which renders as null', () => {
const NullComponent = () => null;
// Testing the whole lifecycle of entering and exiting,
// because those lifecycle methods used to fail when the DOM node was null.
ReactDOM.render(
<TransitionGroup/>,
container,
);
ReactDOM.render(
<TransitionGroup>
<CSSTransition classNames="yolo" timeout={0}>
<NullComponent/>
</CSSTransition>
</TransitionGroup>,
container,
);
ReactDOM.render(
<TransitionGroup/>,
container,
);
});

it('should transition from one to null', () => {
let a = ReactDOM.render(
<TransitionGroup>
Expand Down

1 comment on commit 9cbb3e7

@jbreemhaar
Copy link

Choose a reason for hiding this comment

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

@orfjackal Please also bump package version.

Please sign in to comment.