Skip to content

Commit cb90657

Browse files
Merge branch 'fix/dupe_modal_content' into 'main'
fix: prevent loading multiple modals at the same time See merge request 2pisoftware/cosine/core!431
2 parents 5b2b61a + 1c33a9c commit cb90657

File tree

1 file changed

+10
-4
lines changed
  • system/templates/base/src/js

1 file changed

+10
-4
lines changed

system/templates/base/src/js/app.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// src/app.ts
22
import { AlertAdaptation, DropdownAdaptation, FavouritesAdaptation, TabAdaptation, TableAdaptation } from './adaptations';
3-
import { Autocomplete, Toast as CmfiveToast, CodeMirror, InputWithOther, MultiFileUpload, Overlay, QuillEditor, Tags, TabbedPagination } from './components';
3+
import { Autocomplete, Toast as CmfiveToast, CodeMirror, InputWithOther, MultiFileUpload, Overlay, QuillEditor, TabbedPagination, Tags } from './components';
44

55
import { Modal, Tooltip } from 'bootstrap';
66
import { Sortable } from './components/Sortable';
@@ -86,26 +86,32 @@ export class Cmfive {
8686
}
8787

8888
static openModal(url: string, target: string = '#cmfive-modal') {
89-
Cmfive.currentModal = new Modal(document.getElementById('cmfive-modal')) //, options
89+
const controller = new AbortController();
90+
91+
const container = document.getElementById('cmfive-modal');
92+
Cmfive.currentModal = new Modal(container) //, options
9093

9194
let modalContent = document.querySelector(target + ' .modal-content');
9295
if (modalContent) {
9396
modalContent.innerHTML = '<button type="button" class="btn-close" data-bs-dismiss="modal" data-bs-target="' + target + '" aria-label="Close"></button>';
9497
}
98+
99+
container.addEventListener("hide.bs.modal", () => controller.abort());
95100

96101
Cmfive.currentModal.show();
97102
fetch(url, {
98103
headers: {
99104
'Content-Type': 'application/json'
100-
}
105+
},
106+
signal: controller.signal,
101107
}).then((response) => {
102108
return response.text()
103109
}).then((content) => {
104110
modalContent.innerHTML = content + modalContent.innerHTML;
105111

106112
// https://developer.mozilla.org/en-US/docs/Web/API/Element/innerHTML#security_considerations
107113
// Appending scripts to the DOM via innerHTML is not meant to execute them for security purposes
108-
// Unfortunately, various modals however contian script tags we need to execute
114+
// Unfortunately, various modals however contain script tags we need to execute
109115
modalContent.querySelectorAll("script").forEach(x => {
110116
eval(x.innerHTML);
111117
});

0 commit comments

Comments
 (0)