fix(js): keep the current URL when pushState/replaceState omit url

resolveOrFallback(undefined) returned undefined, so applyVirtual set
__virtualUrl to null and location reverted to the document URL. Per the HTML
spec a missing url keeps the current document URL; return __currentUrl() so the
new history entry captures the current location instead of clearing it.

Fixes #496
This commit is contained in:
Andrey Mnatsakanov committed 2026-07-26 13:30:07 +02:00
1 parent 8078cc3070
commit 1fc5a24e98
2 files changed
+26 -1

No files matched your search

+22
View File
@@ -1317,6 +1317,28 @@ mod tests {
rt
}
#[test]
fn replace_state_without_url_preserves_current_location() {
let mut rt = setup_runtime("<html><body></body></html>");
let path = rt
.evaluate(
"(function(){history.pushState({}, '', '/dashboard'); history.replaceState({scroll:1}); return location.pathname;})()",
)
.unwrap();
assert_eq!(path, serde_json::json!("/dashboard"));
}
#[test]
fn push_state_without_url_preserves_current_location() {
let mut rt = setup_runtime("<html><body></body></html>");
let path = rt
.evaluate(
"(function(){history.pushState({}, '', '/a'); history.pushState({b:1}); return location.pathname;})()",
)
.unwrap();
assert_eq!(path, serde_json::json!("/a"));
}
#[test]
fn test_document_title() {
let mut rt = setup_runtime("<html><head><title>Test</title></head><body></body></html>");