@samitouri / QOS-React-2 / commits / 9dbbaf12bf

ReactTransitionGroup: Fix changing to null child

Fixes #1457. Test Plan: grunt fasttest

Ben Alpert committed Apr 28, 2014 at 20:52 UTC 9dbbaf12bf607eb6e2d77aa80b714c4183c86644
2 files changed +25 -4
src/addons/transitions/ReactTransitionGroup.js
+4 -4
@@ -61,15 +61,15 @@ var ReactTransitionGroup = React.createClass({
61 var key;
62
63 for (key in nextChildMapping) {
64 - if (!prevChildMapping.hasOwnProperty(key) &&
65 - !this.currentlyTransitioningKeys[key]) {
64 + var hasPrev = prevChildMapping && prevChildMapping.hasOwnProperty(key);
65 + if (!hasPrev && !this.currentlyTransitioningKeys[key]) {
66 this.keysToEnter.push(key);
67 }
68 }
69
70 for (key in prevChildMapping) {
71 - if (!nextChildMapping.hasOwnProperty(key) &&
72 - !this.currentlyTransitioningKeys[key]) {
71 + var hasNext = nextChildMapping && nextChildMapping.hasOwnProperty(key);
72 + if (!hasNext && !this.currentlyTransitioningKeys[key]) {
73 this.keysToLeave.push(key);
74 }
75 }
src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js
+21
@@ -142,4 +142,25 @@ describe('ReactCSSTransitionGroup', function() {
142 container
143 );
144 });
145 +
146 + it('should transition from one to null', function() {
147 + var a = React.renderComponent(
148 + <ReactCSSTransitionGroup transitionName="yolo">
149 + <span key="one" id="one" />
150 + </ReactCSSTransitionGroup>,
151 + container
152 + );
153 + expect(a.getDOMNode().childNodes.length).toBe(1);
154 + React.renderComponent(
155 + <ReactCSSTransitionGroup transitionName="yolo">
156 + {null}
157 + </ReactCSSTransitionGroup>,
158 + container
159 + );
160 + // (Here, we expect the original child to stick around but test that no
161 + // exception is thrown)
162 + expect(a.getDOMNode().childNodes.length).toBe(1);
163 + expect(a.getDOMNode().childNodes[0].id).toBe('one');
164 + });
165 +
166 });