From 9dbbaf12bf607eb6e2d77aa80b714c4183c86644 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Mon, 28 Apr 2014 20:52:42 -0300 Subject: [PATCH] ReactTransitionGroup: Fix changing to null child Fixes #1457. Test Plan: grunt fasttest --- .../transitions/ReactTransitionGroup.js | 8 +++---- .../__tests__/ReactCSSTransitionGroup-test.js | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/addons/transitions/ReactTransitionGroup.js b/src/addons/transitions/ReactTransitionGroup.js index 1c43671d9f..f77f63a1cd 100644 --- a/src/addons/transitions/ReactTransitionGroup.js +++ b/src/addons/transitions/ReactTransitionGroup.js @@ -61,15 +61,15 @@ var ReactTransitionGroup = React.createClass({ var key; for (key in nextChildMapping) { - if (!prevChildMapping.hasOwnProperty(key) && - !this.currentlyTransitioningKeys[key]) { + var hasPrev = prevChildMapping && prevChildMapping.hasOwnProperty(key); + if (!hasPrev && !this.currentlyTransitioningKeys[key]) { this.keysToEnter.push(key); } } for (key in prevChildMapping) { - if (!nextChildMapping.hasOwnProperty(key) && - !this.currentlyTransitioningKeys[key]) { + var hasNext = nextChildMapping && nextChildMapping.hasOwnProperty(key); + if (!hasNext && !this.currentlyTransitioningKeys[key]) { this.keysToLeave.push(key); } } diff --git a/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js b/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js index 2bf5da4154..ef06239501 100644 --- a/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js +++ b/src/addons/transitions/__tests__/ReactCSSTransitionGroup-test.js @@ -142,4 +142,25 @@ describe('ReactCSSTransitionGroup', function() { container ); }); + + it('should transition from one to null', function() { + var a = React.renderComponent( + + + , + container + ); + expect(a.getDOMNode().childNodes.length).toBe(1); + React.renderComponent( + + {null} + , + container + ); + // (Here, we expect the original child to stick around but test that no + // exception is thrown) + expect(a.getDOMNode().childNodes.length).toBe(1); + expect(a.getDOMNode().childNodes[0].id).toBe('one'); + }); + });