diff --git a/src/SwitchTransition.js b/src/SwitchTransition.js
index 78dc375d..2a5cb61a 100644
--- a/src/SwitchTransition.js
+++ b/src/SwitchTransition.js
@@ -143,6 +143,7 @@ class SwitchTransition extends React.Component {
static getDerivedStateFromProps(props, state) {
if (props.children == null) {
return {
+ status: ENTERED,
current: null,
};
}
diff --git a/test/SwitchTransition-test.js b/test/SwitchTransition-test.js
index 9250a586..42c35807 100644
--- a/test/SwitchTransition-test.js
+++ b/test/SwitchTransition-test.js
@@ -157,4 +157,47 @@ describe('SwitchTransition', () => {
expect(container.textContent).toBe('second');
});
+
+ it.each([
+ ['out-in', 'exiting'],
+ ['out-in', 'entering'],
+ ['in-out', 'entering'],
+ ['in-out', 'exiting'],
+ ])('handles null children in %s mode while %s', (mode, status) => {
+ const firstRef = React.createRef();
+ const secondRef = React.createRef();
+ const first = (
+
+ {(state) => first: {state}}
+
+ );
+ const second = (
+
+ {(state) => second: {state}}
+
+ );
+ const { container, rerender } = render(
+ {first}
+ );
+
+ rerender({second});
+ if (status === (mode === 'out-in' ? 'entering' : 'exiting')) {
+ act(() => {
+ jest.runOnlyPendingTimers();
+ });
+ }
+ expect(container.textContent).toContain(status);
+
+ rerender({null});
+ act(() => {
+ jest.runAllTimers();
+ });
+ expect(container.textContent).toBe('');
+
+ rerender({first});
+ act(() => {
+ jest.runAllTimers();
+ });
+ expect(container.textContent).toBe('first: entered');
+ });
});