Skip to content

Keep shorthand doc URLs in the address bar on client-side navigation - #794

Merged
mishig25 merged 1 commit into
mainfrom
keep-shorthand-doc-urls
Jul 3, 2026
Merged

Keep shorthand doc URLs in the address bar on client-side navigation#794
mishig25 merged 1 commit into
mainfrom
keep-shorthand-doc-urls

Conversation

@mishig25

@mishig25 mishig25 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

Follow-up to #792. Clicking a shorthand doc link (e.g. /docs/hub/advanced-compute-options) was canonicalizing the address bar to the full /docs/hub/main/en/advanced-compute-options URL. This restores the old svelteKitCustomClient behavior: the URL bar keeps the shorthand the user clicked.

How

SvelteKit's router still needs the expanded path to resolve the route (its external-URL check runs before reroute, see #792), so the click listener in +layout.svelte now:

  1. expands the anchor's pathname just long enough for SvelteKit's click handler to read it (then restores the DOM href),
  2. lets the client-side navigation happen on the expanded route,
  3. in afterNavigate, rewrites the history entry back to the shorthand URL via history.replaceState (equivalent to the old fork pushing originalUrl).

Modified clicks (cmd/ctrl/shift/alt, non-left button, target=) are left untouched, so open-in-new-tab uses the shorthand URL too.

Known caveat (same class of trade-off as the fork removal): pressing back/forward onto a shorthand history entry falls back to a full page load — the server serves the identical page at shorthand URLs, so content is always correct.

Verification

Browser test (Chrome via playwright) on the built accelerate docs — clicking an injected /docs/accelerate/quicktour link:

  • navigates client-side (JS state survives) ✚ renders Quicktour ✅
  • address bar shows /docs/accelerate/quicktour (not /docs/accelerate/main/en/quicktour) ✅
  • the DOM anchor's href is restored to the shorthand ✅

svelte-check: 0 errors, prettier clean.

🤖 Generated with Claude Code

After #792, clicking a shorthand doc link (/docs/lib/page) canonicalized
the address bar to the full /docs/lib/version/lang/page URL. Restore the
old svelteKitCustomClient behavior: SvelteKit still resolves the expanded
path internally (partial loading), but once the navigation completes the
history entry is rewritten back to the shorthand the user clicked. The
anchor's href is also restored right after SvelteKit reads it, and
modified clicks (cmd/ctrl/middle) are left untouched so new tabs open the
shorthand URL.

Caveat: back/forward onto a shorthand history entry falls back to a full
page load (the server serves the same page there).

Verified with a browser test on the built accelerate docs: shorthand
click SPA-navigates AND the address bar shows /docs/accelerate/quicktour.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mishig25
mishig25 merged commit 707e116 into main Jul 3, 2026
5 checks passed
@mishig25
mishig25 deleted the keep-shorthand-doc-urls branch July 3, 2026 21:07
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