mirror of https://github.com/ElemeFE/element
Popper: fix memory leak on route change (#9757)
parent
e4abaf7b6e
commit
1b3832f009
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue