Popper: fix memory leak on route change (#9757)

pull/9771/head
syn-zeta 2018-02-10 18:59:32 -08:00 committed by 杨奕
parent e4abaf7b6e
commit 1b3832f009
2 changed files with 14 additions and 19 deletions

View File

@ -240,7 +240,6 @@
if (typeof this.state.updateCallback === 'function') {
this.state.updateCallback(data);
}
};
/**
@ -438,7 +437,6 @@
popperOffsets.width = popperRect.width;
popperOffsets.height = popperRect.height;
return {
popper: popperOffsets,
reference: referenceOffsets
@ -464,6 +462,7 @@
target = root;
}
target.addEventListener('scroll', this.state.updateBound);
this.state.scrollTarget = target;
}
};
@ -476,13 +475,9 @@
Popper.prototype._removeEventListeners = function() {
// NOTE: 1 DOM access here
root.removeEventListener('resize', this.state.updateBound);
if (this._options.boundariesElement !== 'window') {
var target = getScrollParent(this._reference);
// here it could be both `body` or `documentElement` thanks to Firefox, we then check both
if (target === root.document.body || target === root.document.documentElement) {
target = root;
}
target.removeEventListener('scroll', this.state.updateBound);
if (this._options.boundariesElement !== 'window' && this.state.scrollTarget) {
this.state.scrollTarget.removeEventListener('scroll', this.state.updateBound);
this.state.scrollTarget = null;
}
this.state.updateBound = null;
};

View File

@ -129,9 +129,9 @@ export default {
}
},
doDestroy() {
doDestroy(forceDestroy) {
/* istanbul ignore if */
if (this.showPopper || !this.popperJS) return;
if (!this.popperJS || (this.showPopper && !forceDestroy)) return;
this.popperJS.destroy();
this.popperJS = null;
},
@ -184,7 +184,7 @@ export default {
},
beforeDestroy() {
this.doDestroy();
this.doDestroy(true);
if (this.popperElm && this.popperElm.parentNode === document.body) {
this.popperElm.removeEventListener('click', stop);
document.body.removeChild(this.popperElm);