From fa490337efcf9d6a00b548a9e06c0ce18f40effb Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 28 Feb 2022 11:51:29 +0000 Subject: [PATCH] FIX: Ensure sidebar class is removed when component destroyed (#111) --- .../discourse/components/campaign-banner.js.es6 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/components/campaign-banner.js.es6 b/assets/javascripts/discourse/components/campaign-banner.js.es6 index 6784aa6..064f4af 100644 --- a/assets/javascripts/discourse/components/campaign-banner.js.es6 +++ b/assets/javascripts/discourse/components/campaign-banner.js.es6 @@ -7,6 +7,8 @@ import discourseComputed, { observes } from "discourse-common/utils/decorators"; import { later } from "@ember/runloop"; import { inject as service } from "@ember/service"; +const SIDEBAR_BODY_CLASS = "subscription-campaign-sidebar"; + export default Component.extend({ router: service(), dismissed: false, @@ -68,9 +70,9 @@ export default Component.extend({ didInsertElement() { this._super(...arguments); if (this.isSidebar && this.shouldShow && !this.site.mobileView) { - document.body.classList.add("subscription-campaign-sidebar"); + document.body.classList.add(SIDEBAR_BODY_CLASS); } else { - document.body.classList.remove("subscription-campaign-sidebar"); + document.body.classList.remove(SIDEBAR_BODY_CLASS); } // makes sure to only play animation once, & not repeat on reload @@ -93,6 +95,10 @@ export default Component.extend({ } }, + willDestroyElement() { + document.body.classList.remove(SIDEBAR_BODY_CLASS); + }, + @discourseComputed("backgroundImageUrl") bannerInfoStyle(backgroundImageUrl) { if (!backgroundImageUrl) { @@ -139,7 +145,7 @@ export default Component.extend({ @observes("dismissed") _updateBodyClasses() { if (this.dismissed) { - document.body.classList.remove("subscription-campaign-sidebar"); + document.body.classList.remove(SIDEBAR_BODY_CLASS); } },