forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot-lazily-load-swal.diff
30 lines (27 loc) · 1.02 KB
/
snapshot-lazily-load-swal.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
diff --git a/assets/app.js b/assets/app.js
index 20eca42..2ce8f0e 100644
--- a/assets/app.js
+++ b/assets/app.js
@@ -12,7 +12,6 @@ import './styles/app.css';
import './bootstrap';
import { Modal } from 'bootstrap';
-import Swal from 'sweetalert2';
document.addEventListener('turbo:before-cache', () => {
if (document.body.classList.contains('modal-open')) {
@@ -24,8 +23,14 @@ document.addEventListener('turbo:before-cache', () => {
modal.dispose();
}
- if (Swal.isVisible()) {
- Swal.getPopup().style.animationDuration = '0ms'
- Swal.close();
+ // internal way to see if sweetalert2 has been imported yet
+ if (__webpack_modules__[require.resolveWeak('sweetalert2')]) {
+ // because we know it's been imported, this will run synchronously
+ import('sweetalert2').then((Swal) => {
+ if (Swal.default.isVisible()) {
+ Swal.default.getPopup().style.animationDuration = '0ms'
+ Swal.default.close();
+ }
+ })
}
});