REFACTOR: Remove `Discourse` constants from `cleanDOM`

REFACTOR: Remove Discourse constants from cleanDOM

diff --git a/app/assets/javascripts/discourse/app/initializers/page-tracking.js b/app/assets/javascripts/discourse/app/initializers/page-tracking.js
index df34d9f..6fa0290 100644
--- a/app/assets/javascripts/discourse/app/initializers/page-tracking.js
+++ b/app/assets/javascripts/discourse/app/initializers/page-tracking.js
@@ -15,7 +15,9 @@ export default {
     const router = container.lookup("router:main");
 
     router.on("routeWillChange", viewTrackingRequired);
-    router.on("routeDidChange", cleanDOM);
+    router.on("routeDidChange", () => {
+      cleanDOM(container);
+    });
 
     let appEvents = container.lookup("service:app-events");
     let documentTitle = container.lookup("service:document-title");
diff --git a/app/assets/javascripts/discourse/app/lib/clean-dom.js b/app/assets/javascripts/discourse/app/lib/clean-dom.js
index 82cdb2d..e45419f 100644
--- a/app/assets/javascripts/discourse/app/lib/clean-dom.js
+++ b/app/assets/javascripts/discourse/app/lib/clean-dom.js
@@ -1,4 +1,5 @@
 import { scheduleOnce } from "@ember/runloop";
+
 function _clean() {
   if (window.MiniProfiler) {
     window.MiniProfiler.pageTransition();
@@ -23,18 +24,16 @@ function _clean() {
     .not(".no-blur")
     .blur();
 
-  Discourse.set("contextCount", 0);
-  Discourse.__container__.lookup("route:application").send("closeModal");
+  this.lookup("route:application").send("closeModal");
   const hideDropDownFunction = $("html").data("hide-dropdown");
   if (hideDropDownFunction) {
     hideDropDownFunction();
   }
 
-  // TODO: Avoid container lookup here
-  const appEvents = Discourse.__container__.lookup("service:app-events");
-  appEvents.trigger("dom:clean");
+  this.lookup("service:app-events").trigger("dom:clean");
+  this.lookup("service:document-title").updateContextCount(0);
 }
 
-export function cleanDOM() {
-  scheduleOnce("afterRender", _clean);
+export function cleanDOM(container) {
+  scheduleOnce("afterRender", container, _clean);
 }

GitHub sha: f03f58e5