fix: update ajaxifyTimer logic to only drop the request if the URL is the same as the one it's already processing

re: #12133
This commit is contained in:
Julian Lam
2023-11-01 10:54:41 -04:00
parent 4a5ab081f6
commit b4297cd8f0

View File

@@ -17,6 +17,7 @@ ajaxify.widgets = { render: render };
ajaxify.count = 0; ajaxify.count = 0;
ajaxify.currentPage = null; ajaxify.currentPage = null;
ajaxify.requestedPage = null;
// disables scroll to top when back button is clicked // disables scroll to top when back button is clicked
// https://developer.chrome.com/blog/history-api-scroll-restoration/ // https://developer.chrome.com/blog/history-api-scroll-restoration/
if ('scrollRestoration' in history) { if ('scrollRestoration' in history) {
@@ -38,10 +39,11 @@ ajaxify.widgets = { render: render };
} }
// Abort subsequent requests if clicked multiple times within a short window of time // Abort subsequent requests if clicked multiple times within a short window of time
if (ajaxifyTimer && (Date.now() - ajaxifyTimer) < 500) { if (ajaxify.requestedPage === url && ajaxifyTimer && (Date.now() - ajaxifyTimer) < 500) {
return true; return true;
} }
ajaxifyTimer = Date.now(); ajaxifyTimer = Date.now();
ajaxify.requestedPage = url;
if (ajaxify.handleRedirects(url)) { if (ajaxify.handleRedirects(url)) {
return true; return true;
@@ -134,6 +136,7 @@ ajaxify.widgets = { render: render };
ajaxify.updateHistory = function (url, quiet) { ajaxify.updateHistory = function (url, quiet) {
ajaxify.currentPage = url.split(/[?#]/)[0]; ajaxify.currentPage = url.split(/[?#]/)[0];
ajaxify.requestedPage = null;
if (window.history && window.history.pushState) { if (window.history && window.history.pushState) {
window.history[!quiet ? 'pushState' : 'replaceState']({ window.history[!quiet ? 'pushState' : 'replaceState']({
url: url, url: url,