Skip to content

update page URL and location on pushState/replaceState#2131

Merged
krichprollsch merged 3 commits intomainfrom
pushstate-pathname
Apr 10, 2026
Merged

update page URL and location on pushState/replaceState#2131
krichprollsch merged 3 commits intomainfrom
pushstate-pathname

Conversation

@mookums
Copy link
Copy Markdown
Contributor

@mookums mookums commented Apr 10, 2026

Adapted from #2084.

Original Description:
history.pushState() and replaceState() added entries to the navigation history but didn't update page.url or reinitialize window._location. This meant location.pathname still returned the old path after pushState, breaking SPA routing detection in automation scripts.

The fix adds two lines to both pushState and replaceState in History.zig:

  1. page.url = url to update the page's active URL
  2. page.window._location = try Location.init(url, page) to reinitialize the Location object

This follows the same pattern used during actual navigation (Page.zig lines 477, 560, 895).

replaceState gets the same fix since it had the same gap.

This adds on by fixing the pushState and replaceState by properly resolving the URL before initializing the Location. It also adds a test that ensures the proper behavior and prevents regressions.

tmchow and others added 3 commits April 8, 2026 08:34
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
@krichprollsch krichprollsch merged commit 88dcac6 into main Apr 10, 2026
18 of 23 checks passed
@krichprollsch krichprollsch deleted the pushstate-pathname branch April 10, 2026 15:37
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants