From 6a192206b820bc22a2f143fa4631e3d707d6fa7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Mon, 23 May 2022 20:10:46 +0000 Subject: [PATCH] 8286832: JavaDoc pages call browser history API too often Reviewed-by: prappo --- .../internal/doclets/toolkit/resources/script.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js index b68c774a44d..41f937e63be 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/script.js @@ -137,14 +137,14 @@ document.addEventListener("DOMContentLoaded", function(e) { window.addEventListener("hashchange", function(e) { history.replaceState(contentDiv.scrollTop, document.title); }); + var timeoutId; contentDiv.addEventListener("scroll", function(e) { - var timeoutID; - if (!timeoutID) { - timeoutID = setTimeout(function() { - history.replaceState(contentDiv.scrollTop, document.title); - timeoutID = null; - }, 100); + if (timeoutId) { + clearTimeout(timeoutId); } + timeoutId = setTimeout(function() { + history.replaceState(contentDiv.scrollTop, document.title); + }, 100); }); if (!location.hash) { history.replaceState(contentDiv.scrollTop, document.title);