question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Close sweetalert2 seem not working

See original GitHub issue

I am not sure if I missed something but I can’t close sweetalert2, I found a workaround by manually removing from DOM.

Because with turbolinks when an alert toast is open, and I switch page, and return back, for a second I can still see sweetalert2, from turbolinks cache.

So I am trying to close sweetalert before turbolinks cache page using event:

document.addEventListener("turbolinks:before-cache", function() {
    Swal.close();
})

But this doesn’t work, I can still see sweetalert cached.

I found below workaround which works fine:

document.addEventListener("turbolinks:before-cache", function() {
    document.documentElement.classList.remove('swal2-toast-shown', 'swal2-shown')
    document.querySelector('.swal2-container').remove()
})

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
limontecommented, Oct 18, 2020

I think I understand the issue. The closing isn’t happening instantly because there’s the closing animation which is 0.2s long.

What if you unset the animation and then close a toast? Something like this:

Swal.update({
  hideClass: {
    popup: '',
    backdrop: ''
  }
})
Swal.close()
0reactions
thewebartisan7commented, Oct 26, 2020

@limonte I notice a warning in console:

SweetAlert2: You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.

It’s just a warning so maybe I could ignore it? But this happen when using above solution with Turbolinks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

aurelia - Sweetalert2 won't close - Stack Overflow
I'm using: ... you're right! just to add to this, the problem is in file material-dashboard.css or in plugins_sweetalert2.scss. ... I'm unable to ......
Read more >
SweetAlert2 - a beautiful, responsive, customizable and ...
A beautiful, responsive, customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes.
Read more >
Sweetalert not working - Laracasts
I'm using Sweetalert on Laravel 5.1, when I click on delete button the alert button appears but after 2 or 3 seconds it...
Read more >
SweetAlert2 (Advance version of SweetAlert) - GeeksforGeeks
There is an independent dependency that needs to be installed to work with SweetAlert2. Syntax: function SweetAlert2() { const fireAlert = () => ......
Read more >
[SweetAlert2] Tried on OS11... Don't seems to work.
Had the same problem and had this component to be uploaded on forge on my backlog for a while now. It implements confirmation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found