Skip to content

Commit

Permalink
fix: update ajaxifyTimer logic to only drop the request if the URL is…
Browse files Browse the repository at this point in the history
… the same as the one it's already processing

re: #12133
  • Loading branch information
julianlam authored and barisusakli committed Nov 13, 2023
1 parent 21e5953 commit dcb0c4d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion public/src/ajaxify.js
Expand Up @@ -17,6 +17,7 @@ ajaxify.widgets = { render: render };

ajaxify.count = 0;
ajaxify.currentPage = null;
ajaxify.requestedPage = null;
// disables scroll to top when back button is clicked
// https://developer.chrome.com/blog/history-api-scroll-restoration/
if ('scrollRestoration' in history) {
Expand All @@ -38,10 +39,11 @@ ajaxify.widgets = { render: render };
}

// 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;
}
ajaxifyTimer = Date.now();
ajaxify.requestedPage = url;

if (ajaxify.handleRedirects(url)) {
return true;
Expand Down Expand Up @@ -134,6 +136,7 @@ ajaxify.widgets = { render: render };

ajaxify.updateHistory = function (url, quiet) {
ajaxify.currentPage = url.split(/[?#]/)[0];
ajaxify.requestedPage = null;
if (window.history && window.history.pushState) {
window.history[!quiet ? 'pushState' : 'replaceState']({
url: url,
Expand Down

0 comments on commit dcb0c4d

Please sign in to comment.