2)']);
});
+
+ it('should efficiently unmount & mount components that conditionally return null', () => {
+ function Conditional({ condition }) {
+ return condition ? (
+
+ 2
+ 3
+
+ ) : null;
+ }
+
+ /** @type {() => void} */
+ let toggle;
+ class App extends Component {
+ constructor(props) {
+ super(props);
+ this.state = { condition: true };
+ toggle = () =>
+ this.setState(prevState => ({ condition: !prevState.condition }));
+ }
+
+ render() {
+ const { condition } = this.state;
+ return (
+
+ 1
+
+ {condition ? null : A
}
+ 4
+
+ );
+ }
+ }
+
+ render(
, scratch);
+ expect(scratch.innerHTML).to.equal([1, 2, 3, 4].map(p).join(''));
+
+ clearLog();
+ toggle();
+ rerender();
+
+ expect(scratch.innerHTML).to.equal([1, 'A', 4].map(p).join(''));
+ expectDomLogToBe([
+ '
2.remove()',
+ '
3.remove()',
+ '
.appendChild(#text)',
+ '
14.insertBefore(
A,
4)'
+ ]);
+ });
+
+ it('should efficiently unmount & mount components that conditionally return null with null first child', () => {
+ function Conditional({ condition }) {
+ return condition ? (
+
+ {null}
+ 3
+
+ ) : null;
+ }
+
+ /** @type {() => void} */
+ let toggle;
+ class App extends Component {
+ constructor(props) {
+ super(props);
+ this.state = { condition: true };
+ toggle = () =>
+ this.setState(prevState => ({ condition: !prevState.condition }));
+ }
+
+ render() {
+ const { condition } = this.state;
+ return (
+
+ 1
+
+ {condition ? null : A
}
+ 4
+
+ );
+ }
+ }
+
+ render(, scratch);
+ expect(scratch.innerHTML).to.equal([1, 3, 4].map(p).join(''));
+
+ clearLog();
+ toggle();
+ rerender();
+
+ expect(scratch.innerHTML).to.equal([1, 'A', 4].map(p).join(''));
+ expectDomLogToBe([
+ '
3.remove()',
+ '
.appendChild(#text)',
+ '
14.insertBefore(
A,
4)'
+ ]);
+ });
});