mirror of
https://github.com/filamentphp/filament.git
synced 2026-10-28 03:44:19 +08:00
History state fix (#17971)
* Fix history state helper query string handling * Code style * Improve comments
This commit is contained in:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user