Skip to content

Commit 9e9cd49

Browse files
JoviDeCroockmarvinhagemeister
authored andcommittedMay 28, 2019
fix: should call unmount (preactjs#1647)
1 parent 8a730a6 commit 9e9cd49

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎src/render.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function render(vnode, parentDom, replaceNode) {
2121
diffChildren(
2222
parentDom,
2323
replaceNode ? vnode : (parentDom._prevVNode = vnode),
24-
replaceNode ? undefined : oldVNode,
24+
oldVNode,
2525
EMPTY_OBJ,
2626
parentDom.ownerSVGElement !== undefined,
2727
replaceNode

‎test/browser/render.test.js

+25
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,31 @@ describe('render()', () => {
996996
expect(scratch.innerHTML).to.equal('<div id="a"></div><div id="b"></div><div id="c"></div>');
997997
});
998998

999+
it('should unmount existing components', () => {
1000+
const newScratch = setupScratch();
1001+
const unmount = sinon.spy();
1002+
const mount = sinon.spy();
1003+
class App extends Component {
1004+
componentDidMount() {
1005+
mount();
1006+
}
1007+
1008+
componentWillUnmount() {
1009+
unmount();
1010+
}
1011+
1012+
render() {
1013+
return <div>App</div>;
1014+
}
1015+
}
1016+
render(<div id="a"><App /></div>, newScratch);
1017+
expect(newScratch.innerHTML).to.equal('<div id="a"><div>App</div></div>');
1018+
expect(mount).to.be.calledOnce;
1019+
render(<div id="a">new</div>, newScratch, newScratch.querySelector('#a'));
1020+
expect(newScratch.innerHTML).to.equal('<div id="a">new</div>');
1021+
expect(unmount).to.be.calledOnce;
1022+
});
1023+
9991024
it('should render multiple render roots in one parentDom', () => {
10001025
const childA = scratch.querySelector('#a');
10011026
const childB = scratch.querySelector('#b');

0 commit comments

Comments
 (0)
Please sign in to comment.