@samitouri / QOS-React-2 / commits / 5c9224145e

ReactTransitionGroup: Fix moving from falsey child

See http://stackoverflow.com/q/23510413/49485. Test Plan: grunt fasttest

Ben Alpert committed May 7, 2014 at 09:54 UTC 5c9224145ee0fe2de65e98d2540ccc0f004b1b00
2 files changed +22 -2
src/addons/transitions/ReactTransitionGroup.js
+4 -2
@@ -62,14 +62,16 @@ var ReactTransitionGroup = React.createClass({
62
63 for (key in nextChildMapping) {
64 var hasPrev = prevChildMapping && prevChildMapping.hasOwnProperty(key);
65 - if (!hasPrev && !this.currentlyTransitioningKeys[key]) {
65 + if (nextChildMapping[key] && !hasPrev &&
66 + !this.currentlyTransitioningKeys[key]) {
67 this.keysToEnter.push(key);
68 }
69 }
70
71 for (key in prevChildMapping) {
72 var hasNext = nextChildMapping && nextChildMapping.hasOwnProperty(key);
72 - if (!hasNext && !this.currentlyTransitioningKeys[key]) {
73 + if (prevChildMapping[key] && !hasNext &&
74 + !this.currentlyTransitioningKeys[key]) {
75 this.keysToLeave.push(key);
76 }
77 }
src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
+18
@@ -163,4 +163,22 @@ describe('ReactCSSTransitionGroup', function() {
163 expect(a.getDOMNode().childNodes[0].id).toBe('one');
164 });
165
166 + it('should transition from false to one', function() {
167 + var a = React.renderComponent(
168 + <ReactCSSTransitionGroup transitionName="yolo">
169 + {false}
170 + </ReactCSSTransitionGroup>,
171 + container
172 + );
173 + expect(a.getDOMNode().childNodes.length).toBe(0);
174 + React.renderComponent(
175 + <ReactCSSTransitionGroup transitionName="yolo">
176 + <span key="one" id="one" />
177 + </ReactCSSTransitionGroup>,
178 + container
179 + );
180 + expect(a.getDOMNode().childNodes.length).toBe(1);
181 + expect(a.getDOMNode().childNodes[0].id).toBe('one');
182 + });
183 +
184 });