Skip to content

Commit 817de42

Browse files
committed
Fix error thrown with Preact@8
Occurs when `CSSTransitionGroup` is provided with `children` containing `null`
1 parent 14d8435 commit 817de42

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/CSSTransitionGroup.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313

1414
import { h, cloneElement, Component } from 'preact';
15-
import { getKey } from './util';
15+
import { getKey, filterNullChildren } from './util';
1616
import { mergeChildMappings, isShownInChildren, isShownInChildrenByKey, inChildren, inChildrenByKey } from './TransitionChildMapping';
1717
import { CSSTransitionGroupChild } from './CSSTransitionGroupChild';
1818

@@ -42,10 +42,10 @@ export class CSSTransitionGroup extends Component {
4242
}
4343

4444
componentWillReceiveProps({ children, exclusive, showProp }) {
45-
let nextChildMapping = (children || []).slice();
45+
let nextChildMapping = filterNullChildren(children || []).slice();
4646

4747
// last props children if exclusive
48-
let prevChildMapping = exclusive ? this.props.children : this.state.children;
48+
let prevChildMapping = filterNullChildren(exclusive ? this.props.children : this.state.children);
4949

5050
let newChildren = mergeChildMappings(
5151
prevChildMapping,
@@ -118,7 +118,7 @@ export class CSSTransitionGroup extends Component {
118118

119119
_handleDoneEntering(key) {
120120
delete this.currentlyTransitioningKeys[key];
121-
let currentChildMapping = this.props.children,
121+
let currentChildMapping = filterNullChildren(this.props.children),
122122
showProp = this.props.showProp;
123123
if (!currentChildMapping || (
124124
!showProp && !inChildrenByKey(currentChildMapping, key)
@@ -157,7 +157,7 @@ export class CSSTransitionGroup extends Component {
157157
_handleDoneLeaving(key) {
158158
delete this.currentlyTransitioningKeys[key];
159159
let showProp = this.props.showProp,
160-
currentChildMapping = this.props.children;
160+
currentChildMapping = filterNullChildren(this.props.children);
161161
if (showProp && currentChildMapping &&
162162
isShownInChildrenByKey(currentChildMapping, key, showProp)) {
163163
this.performEnter(key);
@@ -200,7 +200,7 @@ export class CSSTransitionGroup extends Component {
200200
render({ component:Component, transitionName, transitionEnter, transitionLeave, children:c, ...props }, { children }) {
201201
return (
202202
<Component {...props}>
203-
{ children.map(this.renderChild) }
203+
{ filterNullChildren(children).map(this.renderChild) }
204204
</Component>
205205
);
206206
}

src/util.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ export function getComponentBase(component) {
99
export function onlyChild(children) {
1010
return children && children[0];
1111
}
12+
13+
export function filterNullChildren(children) {
14+
return children && children.filter(i => i !== null);
15+
}

0 commit comments

Comments
 (0)