Skip to content

Commit a4d290b

Browse files
committed
fix navigation shortcut URL stitching
1 parent f69c0cc commit a4d290b

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/browser/page.zig

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const Http = @import("../http/Http.zig");
3434
const ScriptManager = @import("ScriptManager.zig");
3535
const SlotChangeMonitor = @import("SlotChangeMonitor.zig");
3636
const HTMLDocument = @import("html/document.zig").HTMLDocument;
37+
3738
const NavigationKind = @import("navigation/navigation.zig").NavigationKind;
39+
const NavigationCurrentEntryChangeEvent = @import("navigation/navigation.zig").NavigationCurrentEntryChangeEvent;
3840

3941
const js = @import("js/js.zig");
4042
const URL = @import("../url.zig").URL;
@@ -737,9 +739,6 @@ pub const Page = struct {
737739
var self: *Page = @ptrCast(@alignCast(ctx));
738740
self.clearTransferArena();
739741

740-
// We need to handle different navigation types differently.
741-
try self.session.navigation.processNavigation(self);
742-
743742
switch (self.mode) {
744743
.pre => {
745744
// Received a response without a body like: https://httpbin.io/status/200
@@ -818,6 +817,9 @@ pub const Page = struct {
818817
unreachable;
819818
},
820819
}
820+
821+
// We need to handle different navigation types differently.
822+
try self.session.navigation.processNavigation(self);
821823
}
822824

823825
fn pageErrorCallback(ctx: *anyopaque, err: anyerror) void {
@@ -1021,22 +1023,19 @@ pub const Page = struct {
10211023
// specifically for this type of lifetime.
10221024
pub fn navigateFromWebAPI(self: *Page, url: []const u8, opts: NavigateOpts, kind: NavigationKind) !void {
10231025
const session = self.session;
1026+
const stitched_url = try URL.stitch(session.transfer_arena, url, self.url.raw, .{ .alloc = .always });
10241027

10251028
// Force will force a page load.
1026-
//
1027-
// TODO: This needs to be reworked but just ensuring events get fired right.
1029+
// Otherwise, we need to check if this is a true navigation.
10281030
if (!opts.force) {
10291031
// If we are navigating within the same document, just change URL.
1030-
const new_url = try URL.parse(url, null);
1031-
if (try self.url.eqlDocument(&new_url, self.arena)) {
1032-
const new_duped_url = try session.arena.dupe(u8, url);
1033-
self.url = try URL.parse(new_duped_url, null);
1032+
const new_url = try URL.parse(stitched_url, null);
1033+
1034+
if (try self.url.eqlDocument(&new_url, session.transfer_arena)) {
1035+
self.url = new_url;
10341036

1035-
// TODO: remove this temporary snippet.
10361037
const prev = session.navigation.currentEntry();
1037-
const NavigationCurrentEntryChangeEvent = @import("navigation/navigation.zig").NavigationCurrentEntryChangeEvent;
10381038
NavigationCurrentEntryChangeEvent.dispatch(&self.session.navigation, prev, kind);
1039-
10401039
return;
10411040
}
10421041
}
@@ -1063,7 +1062,7 @@ pub const Page = struct {
10631062

10641063
session.queued_navigation = .{
10651064
.opts = opts,
1066-
.url = try URL.stitch(session.transfer_arena, url, self.url.raw, .{ .alloc = .always }),
1065+
.url = stitched_url,
10671066
};
10681067

10691068
session.navigation_kind = kind;

0 commit comments

Comments
 (0)