Skip to content

Commit

Permalink
Never fire the callback in sirius.ready twice
Browse files Browse the repository at this point in the history
Sometimes the DOMContentLoaded event is fired after document.readyState already changed to 'interactive'. In this case, the callback is actually called twice with our approach.

This commit ensures that the callback is only called once.

Fixes: SE-14083
  • Loading branch information
jmuscireum committed Oct 9, 2024
1 parent 32449d3 commit e446648
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/main/resources/default/assets/common/core.js.pasta
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ sirius.isFilled = function (value) {
* @param callback the callback to execute once the DOM is completely ready
*/
sirius.ready = function (callback) {
// Add as listener in case DOM is loading...
document.addEventListener("DOMContentLoaded", callback);
// Call manually is we're late...
if (document.readyState === "interactive" || document.readyState === "complete") {
if (document.readyState === "loading") {
// Add as listener in case DOM is loading...
document.addEventListener("DOMContentLoaded", callback);
} else {
// Call manually if we're late...
callback();
}
}
Expand Down

0 comments on commit e446648

Please sign in to comment.