Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limit scrolling history.replaceState #134

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/web/skeleton/Wt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,28 @@ if (html5History) {
// state anymore at the moment that onPopState() is called.
// For navigation, when pushState() is called, the scroll
// history can be updated before the pushState() call.
function coalesceEvents(callback, minPeriod) {
var timer = null;
var args = null;

function dispatch()
{
callback.apply(null, args);
timer = null;
args = null;
}

function proxy() {
args = arguments;

if (!timer) {
timer = setTimeout(dispatch, minPeriod);
}
}

return proxy;
}

function updateScrollHistory() {
//console.log("updateScrollHistory");
try {
Expand All @@ -1961,7 +1983,7 @@ if (html5History) {
console.log(error.toString());
}
}
window.addEventListener('scroll', updateScrollHistory);
window.addEventListener('scroll', coalesceEvents(updateScrollHistory, 10));

// the 'auto' scrollRestoration gives too much flicker, since it
// updates the scroll state before the page is updated
Expand Down
Loading