DEV: Fix flaky d-editor test (#13005)

DEV: Fix flaky d-editor test (#13005)

diff --git a/app/assets/javascripts/discourse/app/components/d-editor.js b/app/assets/javascripts/discourse/app/components/d-editor.js
index ae1a566..3457777 100644
--- a/app/assets/javascripts/discourse/app/components/d-editor.js
+++ b/app/assets/javascripts/discourse/app/components/d-editor.js
@@ -438,7 +438,7 @@ export default Component.extend({
       }
 
       schedule("afterRender", () => {
-        if (this._state !== "inDOM") {
+        if (this._state !== "inDOM" || !this.element) {
           return;
         }
         const $preview = $(this.element.querySelector(".d-editor-preview"));
@@ -653,6 +653,10 @@ export default Component.extend({
 
   _selectText(from, length, opts = { scroll: true }) {
     next(() => {
+      if (!this.element) {
+        return;
+      }
+
       const textarea = this.element.querySelector("textarea.d-editor-input");
       const $textarea = $(textarea);
       textarea.selectionStart = from;

GitHub sha: 81616fbd

This commit appears in #13005 which was approved by eviltrout. It was merged by pmusaraj.