From 574264aaff2a422725e6e8830172bb7ec52034e6 Mon Sep 17 00:00:00 2001 From: Trevin Chow Date: Fri, 3 Apr 2026 16:18:49 -0700 Subject: [PATCH] fix: update page URL and location on pushState/replaceState history.pushState() and replaceState() updated the navigation entry but did not update page.url or reinitialize window.location. This caused location.pathname to return the old value after pushState, breaking SPA routing detection in automation scripts. Both methods now set page.url and re-init the Location object after updating the navigation history. Fixes #2081 Ref #2043 --- src/browser/webapi/History.zig | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/browser/webapi/History.zig b/src/browser/webapi/History.zig index 12336f2c..a5016795 100644 --- a/src/browser/webapi/History.zig +++ b/src/browser/webapi/History.zig @@ -20,6 +20,7 @@ const std = @import("std"); const js = @import("../js/js.zig"); const Page = @import("../Page.zig"); +const Location = @import("Location.zig"); const PopStateEvent = @import("event/PopStateEvent.zig"); const History = @This(); @@ -55,6 +56,10 @@ pub fn pushState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8 const json = state.toJson(arena) catch return error.DataClone; _ = try page._session.navigation.pushEntry(url, .{ .source = .history, .value = json }, page, true); + + // Update page URL and location so that location.pathname reflects the pushed state + page.url = url; + page.window._location = try Location.init(url, page); } pub fn replaceState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const u8, page: *Page) !void { @@ -63,6 +68,10 @@ pub fn replaceState(_: *History, state: js.Value, _: ?[]const u8, _url: ?[]const const json = state.toJson(arena) catch return error.DataClone; _ = try page._session.navigation.replaceEntry(url, .{ .source = .history, .value = json }, page, true); + + // Update page URL and location so that location.pathname reflects the replaced state + page.url = url; + page.window._location = try Location.init(url, page); } fn goInner(delta: i32, page: *Page) !void {