changeLocation on nav

This commit is contained in:
Muki Kiboigo
2025-11-03 09:16:49 -08:00
parent 3cc53b579b
commit 38c6a9bd9d
2 changed files with 12 additions and 2 deletions

View File

@@ -52,7 +52,7 @@ pub const Location = struct {
current_url;
const normalized_hash = std.mem.trimStart(u8, hash, "#");
const new_url = try std.fmt.allocPrint(page.session.transfer_arena, "{s}#{s}", .{ base_without_hash, normalized_hash });
const new_url = try std.fmt.allocPrint(page.arena, "{s}#{s}", .{ base_without_hash, normalized_hash });
return page.navigateFromWebAPI(new_url, .{ .reason = .script }, .replace);
}

View File

@@ -1065,7 +1065,15 @@ pub const Page = struct {
// specifically for this type of lifetime.
pub fn navigateFromWebAPI(self: *Page, url: []const u8, opts: NavigateOpts, kind: NavigationKind) !void {
const session = self.session;
const stitched_url = try URL.stitch(session.transfer_arena, url, self.url.raw, .{ .alloc = .always });
const stitched_url = try URL.stitch(
session.transfer_arena,
url,
self.url.raw,
.{
.alloc = .always,
.null_terminated = true,
},
);
// Force will force a page load.
// Otherwise, we need to check if this is a true navigation.
@@ -1075,6 +1083,8 @@ pub const Page = struct {
if (try self.url.eqlDocument(&new_url, session.transfer_arena)) {
self.url = new_url;
try self.window.changeLocation(self.url.raw, self);
try session.navigation.updateEntries(stitched_url, kind, self, true);
return;
}