Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popper: Fix memory leak on route change (#7715) #9757

Merged
merged 1 commit into from
Feb 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions src/utils/popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@
if (typeof this.state.updateCallback === 'function') {
this.state.updateCallback(data);
}

};

/**
Expand Down Expand Up @@ -438,7 +437,6 @@
popperOffsets.width = popperRect.width;
popperOffsets.height = popperRect.height;


return {
popper: popperOffsets,
reference: referenceOffsets
Expand All @@ -464,6 +462,7 @@
target = root;
}
target.addEventListener('scroll', this.state.updateBound);
this.state.scrollTarget = target;
}
};

Expand All @@ -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;
};
Expand Down Expand Up @@ -519,13 +514,13 @@
var scrollParent = getScrollParent(this._popper);
var offsetParentRect = getOffsetRect(offsetParent);

// Thanks the fucking native API, `document.body.scrollTop` & `document.documentElement.scrollTop`
var getScrollTopValue = function (element) {
return element == document.body ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : element.scrollTop;
}
var getScrollLeftValue = function (element) {
return element == document.body ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : element.scrollLeft;
}
// Thanks the fucking native API, `document.body.scrollTop` & `document.documentElement.scrollTop`
var getScrollTopValue = function (element) {
return element == document.body ? Math.max(document.documentElement.scrollTop, document.body.scrollTop) : element.scrollTop;
}
var getScrollLeftValue = function (element) {
return element == document.body ? Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) : element.scrollLeft;
}

// if the popper is fixed we don't have to substract scrolling from the boundaries
var scrollTop = data.offsets.popper.position === 'fixed' ? 0 : getScrollTopValue(scrollParent);
Expand Down
6 changes: 3 additions & 3 deletions src/utils/vue-popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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);
Expand Down