Skip to content

fix: update page URL and location on pushState/replaceState#2084

Closed
tmchow wants to merge 1 commit intolightpanda-io:mainfrom
tmchow:fix/2081-pushstate-pathname
Closed

fix: update page URL and location on pushState/replaceState#2084
tmchow wants to merge 1 commit intolightpanda-io:mainfrom
tmchow:fix/2081-pushstate-pathname

Conversation

@tmchow
Copy link
Copy Markdown
Contributor

@tmchow tmchow commented Apr 3, 2026

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.

Fixes #2081
Ref #2043

This contribution was developed with AI assistance (Claude Code).

Compound Engineering

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 lightpanda-io#2081
Ref lightpanda-io#2043
@mookums
Copy link
Copy Markdown
Contributor

mookums commented Apr 10, 2026

Thank you for the PR! Adapted to #2131 with some modifications.

@mookums mookums closed this Apr 10, 2026
@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.

history.pushState does not update location.pathname

2 participants