FIX: Docking mixin was not cleaning up timers (#12638)

I noticed this while trying to debug slow performing ember tests.
Our docking mixin sometimes sets timers but never cancels them when
removed. I'm not sure of any errors this causes but we should be tidying
up whenever the component is removed.
This commit is contained in:
Robin Ward 2021-04-15 21:33:19 -04:00 committed by GitHub
parent e08432ddde
commit 42f6c9b6b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import Mixin from "@ember/object/mixin";
import discourseDebounce from "discourse-common/lib/debounce";
import { later } from "@ember/runloop";
import { cancel, later } from "@ember/runloop";
const helper = {
offset() {
@ -12,11 +12,13 @@ const helper = {
export default Mixin.create({
queueDockCheck: null,
_initialTimer: null,
_queuedTimer: null,
init() {
this._super(...arguments);
this.queueDockCheck = () => {
discourseDebounce(this, this.safeDockCheck, 5);
this._queuedTimer = discourseDebounce(this, this.safeDockCheck, 5);
};
},
@ -34,11 +36,17 @@ export default Mixin.create({
$(document).bind("touchmove.discourse-dock", this.queueDockCheck);
// dockCheck might happen too early on full page refresh
later(this, this.safeDockCheck, 50);
this._initialTimer = later(this, this.safeDockCheck, 50);
},
willDestroyElement() {
this._super(...arguments);
if (this._queuedTimer) {
cancel(this._queuedTimer);
}
cancel(this._initialTimer);
$(window).unbind("scroll.discourse-dock", this.queueDockCheck);
$(document).unbind("touchmove.discourse-dock", this.queueDockCheck);
},