nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: sweetalert2/sweetalert2
Pull request #2655 (2023-07-15 14:45:54)

fix: check if texarea is still in document
fixes https://github.com/sweetalert2/sweetalert2/issues/2653#issuecomment-1635954193


Patch:
diff --git a/src/utils/dom/renderers/renderInput.js b/src/utils/dom/renderers/renderInput.js
index 9ab9f1e7..018353c5 100644
--- a/src/utils/dom/renderers/renderInput.js
+++ b/src/utils/dom/renderers/renderInput.js
@@ -268,6 +268,10 @@ renderInputType.textarea = (textarea, params) => {
     if ('MutationObserver' in window) {
       const initialPopupWidth = parseInt(window.getComputedStyle(dom.getPopup()).width)
       const textareaResizeHandler = () => {
+        // check if texarea is still in document (i.e. popup wasn't closed in the meantime)
+        if (!document.body.contains(textarea)) {
+          return
+        }
         const textareaWidth = textarea.offsetWidth + getMargin(textarea)
         if (textareaWidth > initialPopupWidth) {
           dom.getPopup().style.width = `${textareaWidth}px`


Test patch:
diff --git a/cypress/e2e/inputs.cy.js b/cypress/e2e/inputs.cy.js
index 07cab5e4..6ee0068c 100644
--- a/cypress/e2e/inputs.cy.js
+++ b/cypress/e2e/inputs.cy.js
@@ -388,6 +388,24 @@ describe('Inputs', () => {
     }, 20)
   })
 
+  it('should not fail if textarea value is a promise and popup is closed before the promise is resolved', (done) => {
+    SwalWithoutAnimation.fire({
+      input: 'textarea',
+      width: 600,
+      inputValue: new Promise((resolve) => {
+        setTimeout(() => {
+          resolve('foo')
+        }, 10)
+      }),
+      didOpen: () => {
+        Swal.close()
+      },
+    })
+    setTimeout(() => {
+      done()
+    }, 20)
+  })
+
   it('returnInputValueOnDeny: true should pass the input value as result.value', (done) => {
     SwalWithoutAnimation.fire({
       input: 'text',