From 0c549af30768058c35ad54d37ea3967ccef39284 Mon Sep 17 00:00:00 2001
From: Nikhil Tanwar <2002nikhiltanwar@gmail.com>
Date: Sat, 25 Jun 2022 18:14:42 +0530
Subject: [PATCH] Add check to not add same link in session history
Previously, if the following steps were executed:
1. Click a book tile/visit an unrelated link from the address bar
2. Press back button
Then forward history was discarded (forward button gets disabled).
This happened because of the window.history.pushState on every window.onload event. This led to the same link being added in history and thus discarding the previous "forward-history"
This change adds a condition to only push the current state if the queries are not same.
---
static/skin/index.js | 6 +++++-
test/server.cpp | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/static/skin/index.js b/static/skin/index.js
index 8f5ed557b..2b5a4149d 100644
--- a/static/skin/index.js
+++ b/static/skin/index.js
@@ -429,7 +429,11 @@
filter.addEventListener('change', () => {resetAndFilter(filter.name, filter.value)});
});
if (filters) {
- window.history.pushState({}, null, `?${params.toString()}`);
+ const currentLink = window.location.search;
+ const newLink = `?${params.toString()}`;
+ if (currentLink != newLink) {
+ window.history.pushState({}, null, newLink);
+ }
}
updateVisibleParams();
document.getElementById('kiwixSearchForm').onsubmit = (event) => {event.preventDefault()};
diff --git a/test/server.cpp b/test/server.cpp
index 12909fe64..992ffb9c5 100644
--- a/test/server.cpp
+++ b/test/server.cpp
@@ -184,7 +184,7 @@ R"EXPECTEDRESULT( src="/ROOT/skin/jquery-ui/external/jquery/jquery.js?cache
src: url("/ROOT/skin/fonts/Roboto.ttf?cacheid=84d10248") format("truetype");
-
+
)EXPECTEDRESULT"
},
{