FIX: CookText may be gone before promise resolves (#10097)

FIX: CookText may be gone before promise resolves (#10097)

  • FIX: CookText may be gone before promise resolves

Bug introduced in 293467a37ae33c5fd8fd40bbfc05bffa578b90ed.

  • DEV: Drop the window.requireModule in cook-text

It was introduced in 2017 in 232311aa8c8e879c98dc061ac1755ee4d0dd9b0f but doesn’t seem to be necessary anymore.

diff --git a/app/assets/javascripts/discourse/app/components/cook-text.js b/app/assets/javascripts/discourse/app/components/cook-text.js
index 2019954..be89fc8 100644
--- a/app/assets/javascripts/discourse/app/components/cook-text.js
+++ b/app/assets/javascripts/discourse/app/components/cook-text.js
@@ -1,7 +1,7 @@
-import { next } from "@ember/runloop";
 import Component from "@ember/component";
 import { cookAsync } from "discourse/lib/text";
 import { ajax } from "discourse/lib/ajax";
+import { resolveAllShortUrls } from "pretty-text/upload-short-url";
 
 const CookText = Component.extend({
   cooked: null,
@@ -10,13 +10,10 @@ const CookText = Component.extend({
     this._super(...arguments);
     cookAsync(this.rawText).then(cooked => {
       this.set("cooked", cooked);
-      // no choice but to defer this cause
-      // pretty text may only be loaded now
-      next(() =>
-        window
-          .requireModule("pretty-text/upload-short-url")
-          .resolveAllShortUrls(ajax, this.siteSettings, this.element)
-      );
+
+      if (this.element && !this.isDestroying && !this.isDestroyed) {
+        return resolveAllShortUrls(ajax, this.siteSettings, this.element);
+      }
     });
   }
 });

GitHub sha: 3b51e05d

1 Like

This commit appears in #10097 which was approved by davidtaylorhq and eviltrout. It was merged by CvX.