From 578145acd64f72e96fbd00056bc1e736c482dd34 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 27 Jan 2022 21:09:40 -0500 Subject: [PATCH] fix: bug where page wouldn't complete loading if data.scripts was emptied --- public/src/ajaxify.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/public/src/ajaxify.js b/public/src/ajaxify.js index 6181af8357..04bcb6949e 100644 --- a/public/src/ajaxify.js +++ b/public/src/ajaxify.js @@ -344,7 +344,7 @@ ajaxify = window.ajaxify || {}; // Require and parse modules let outstanding = data.scripts.length; - data.scripts.map(function (script) { + const scripts = data.scripts.map(function (script) { if (typeof script === 'function') { return function (next) { script(); @@ -369,14 +369,20 @@ ajaxify = window.ajaxify || {}; }; } return null; - }).filter(Boolean).forEach(function (fn) { - fn(function () { - outstanding -= 1; - if (outstanding === 0) { - callback(); - } + }).filter(Boolean); + + if (scripts.length) { + scripts.forEach(function (fn) { + fn(function () { + outstanding -= 1; + if (outstanding === 0) { + callback(); + } + }); }); - }); + } else { + callback(); + } }); };