Skip to content

Commit

Permalink
Merge 6c38ced into d63b740
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Mar 29, 2019
2 parents d63b740 + 6c38ced commit 2670acd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/diff/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ export function unmount(vnode, ancestorComponent, skipRemove) {
applyRef(r, null, ancestorComponent);
}

if (!skipRemove && vnode._lastDomChild==null && (skipRemove = ((r = vnode._dom)!=null))) removeNode(r);
let dom;
if (!skipRemove && vnode._lastDomChild==null) {
skipRemove = (dom = vnode._dom)!=null;
}

vnode._dom = vnode._lastDomChild = null;

Expand All @@ -332,6 +335,8 @@ export function unmount(vnode, ancestorComponent, skipRemove) {
unmount(r[i], ancestorComponent, skipRemove);
}
}

if (dom!=null) removeNode(dom);
}

/** The `.render()` method for a PFC backing instance. */
Expand Down
17 changes: 16 additions & 1 deletion test/browser/lifecycle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ describe('Lifecycle methods', () => {
expect(stateArg).to.deep.equal({
value: 3
});

// New Props (see #1446)
// 4 -> 5 in gDSFP
render(<Foo foo="baz" />, scratch);
Expand Down Expand Up @@ -1384,6 +1384,21 @@ describe('Lifecycle methods', () => {
render(<div />, scratch);
expect(Bar.prototype.componentWillUnmount, 'when removed').to.have.been.calledOnce;
});

it('should only remove dom after componentWillUnmount was called', () => {
class Foo extends Component {
componentWillUnmount() {
expect(document.getElementById('foo')).to.not.equal(null);
}

render() {
return <div id="foo" />;
}
}

render(<Foo />, scratch);
render(null, scratch);
});
});


Expand Down

0 comments on commit 2670acd

Please sign in to comment.