From 142ad75bc360eacf995984a5ca5113a186377987 Mon Sep 17 00:00:00 2001 From: Ivan Kuchin Date: Fri, 19 Dec 2025 16:53:09 +0100 Subject: [PATCH] don't push state with same url Currently navigating through documentation sometimes leads to duplicate history entries, also when navigating back to documentation page either from another documentation page or from different site, pushState not only add additional entry, but also removes all history in front. Ensuring that pushState is done only if new url is not equal current resolves this. I see only one quirky downside - it is not possible to create multiple history entries by navigating to same documentation page. --- src/utils/common-utils.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/utils/common-utils.js b/src/utils/common-utils.js index 7ff67e6e..e20d1bfd 100644 --- a/src/utils/common-utils.js +++ b/src/utils/common-utils.js @@ -151,8 +151,11 @@ export function replaceState(rawElementId) { const newQuery = query.toString().length > 1 ? `${query.toString()}&route=${elementId}` : `route=${elementId}`; const fragment = `#${currentNavigationHashPart}?${newQuery}`; - const url = new URL(fragment, window.location.href); - window.history.pushState(null, null, url.href); + const currentHref = window.location.href; + const url = new URL(fragment, currentHref); + if (url.href !== currentHref) { + window.history.pushState(null, null, url.href); + } } export function toMarkdown(markdownStringRaw) {