Skip to content

fix: follow nav redirects - #92

Merged
lukeed merged 2 commits into
mainfrom
fix/client-redirects
Nov 3, 2026
Merged

lukeed merged 2 commits into
mainfrom
fix/client-redirects

Conversation

@lukeed

@lukeed lukeed commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

A link that the server redirects, such as /blog/post to /blog/post/, kept its first URL after a client navigation. The address bar, the history entry, and each relative URL of the page then did not match the page, as they would after a full-page load.

  • html.read() gives a page: its HTML, and the URL of the last response, with the hash of the link, since a request carries no hash. Prefetch keeps the same page, and resolves the stylesheets of a page against its final URL.
  • Navigation: for push and replace, when the browser has NavigationPrecommitController, the client fetches the page in precommitHandler, and calls controller.redirect() when the URL changed. The URL then commits as the final one, before the swap. Traverse navigations, and browsers without precommitHandler, get a full-page load of the final URL when a response was redirected, as the client already does for a response that is not HTML.
  • A fetch that fails before the commit no longer leaves the new URL on the old page.
  • Events: bongo:navigate fires in the navigate listener, for every navigation, so it always comes before the URL changes and before the fetch. On main, it came after the URL changed. After a redirect, bongo:navigate gets the URL of the link, and bongo:replace, bongo:replaced, and bongo:navigated get the final URL.
  • Docs: a "Redirects" section in the client runtime page.

Performance

  • Client runtime, minified and gzipped: 3,371 B → 3,559 B (+188 B).
  • Time of 30 client navigations in Chrome 156, main against this branch, in both orders: median 297.4 ms / 294.4 ms, then 298.1 ms / 297.7 ms. No change; the fade transition is most of it.
  • bun run bench site: 2.35 s, against 2.34 s on main. No change.

Test plan

  • A redirect commits the final URL, with the hash of the link, before the page swaps (precommitHandler stub)
  • Without precommitHandler, a redirect loads the final URL
  • bongo:navigate sees the old URL in location, with and without precommitHandler, and on back and forward (fails on the first commit of this PR)
  • Prefetch keeps the URL that a redirect ends at
  • In Chrome 156: a link without its trailing slash shows the URL with the slash after a client navigation, and back and forward work
  • bun run build, bun test, bunx tsc -p ., bunx tsc -p build

A link that redirects, such as /blog/post to /blog/post/, kept its
old URL after a client navigation, so the address bar and relative
URLs did not match the page. The client now commits the final URL
with precommitHandler, or loads the page when the URL is already
committed.
bongo:navigate fired from the fetch, so it came before the URL
changed in a browser with precommitHandler, and after it in others
and on back and forward. It now fires in the navigate listener, for
every navigation: before the URL changes and before the fetch.
@lukeed lukeed mentioned this pull request Nov 3, 2026
3 tasks done
@lukeed
lukeed merged commit f24bbde into main Nov 3, 2026
4 checks passed
@lukeed
lukeed deleted the fix/client-redirects branch November 3, 2026 02:37
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