Skip to content

fix: skip history.pushState - #90

Merged
lukeed merged 2 commits into
mainfrom
fix/client-history
Oct 27, 2026
Merged

lukeed merged 2 commits into
mainfrom
fix/client-history

Conversation

@lukeed

@lukeed lukeed commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Summary

The client took each history.pushState() or history.replaceState() from a script as a navigation, and fetched the URL as a page. A tab or filter that wrote its state into the URL lost it, a script that strips utm_* with replaceState reloaded the page, and a URL with no page failed. Back or forward between entries of one page also fetched the page again.

Now the client works as the browser does without it:

  • A push or replace with destination.sameDocument comes from the History API, so the client leaves it to the page. Links and navigate() have sameDocument: false, and still go through the client.
  • The client records the page of each history entry. Back or forward to an entry of the page on screen keeps it, and the page gets its popstate. Back or forward to an entry of another page loads that page.

Test plan

  • By hand in Chromium (Playwright), on a site with a tab widget that calls pushState('?tab=2'): before, each pushState, back, and forward fetched the page and reset the tab; after, none fetch and the tab keeps its state. A client link, and back to an entry of another page, still fetch.
  • Unit tests: a scripted push or replace is not intercepted; back or forward is intercepted only for an entry of another page
  • bun run build, bun test (905 pass), bunx tsc -p ., bunx tsc -p build

The client took each history.pushState or replaceState from a script
as a navigation, and fetched the URL as a page: a widget that put its
state in the URL lost it, and a URL with no page failed. Back or forward
within one page also fetched it again. Now only a navigation to another
page, or back or forward to an entry of another page, loads a page.
@lukeed
lukeed merged commit 9220693 into main Oct 27, 2026
4 checks passed
@lukeed
lukeed deleted the fix/client-history branch October 27, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant