History state fix (#17971)

* Fix history state helper query string handling

* Code style

* Improve comments
This commit is contained in:
Raj Siva-Rajah
2025-09-28 21:30:49 +01:00
committed by GitHub
parent bf8fbbff35
commit 805137fa85
2 changed files with 17 additions and 5 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+16 -4
View File
@@ -6,16 +6,28 @@ window.history.replaceState = function (state, unused, url) {
state.url = state.url.toString()
}
const targetUrl = url || state?.url || window.location.href
const currentUrl = window.location.href
// Always update if the URL has changed
if (targetUrl !== currentUrl) {
originalReplaceState.call(window.history, state, unused, url)
return
}
// Skip duplicate `replaceState()` calls
try {
if (JSON.stringify(state) === JSON.stringify(window.history.state)) {
return
const currentState = window.history.state
const stateChanged =
JSON.stringify(state) !== JSON.stringify(currentState)
if (stateChanged) {
originalReplaceState.call(window.history, state, unused, url)
}
} catch (error) {
// If comparison fails, proceed with the update
originalReplaceState.call(window.history, state, unused, url)
}
originalReplaceState.call(window.history, state, unused, url)
}
window.history.pushState = function (state, unused, url) {