Keep shorthand doc URLs in the address bar on client-side navigation - #794
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-optionsURL. This restores the oldsvelteKitCustomClientbehavior: 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.sveltenow:afterNavigate, rewrites the history entry back to the shorthand URL viahistory.replaceState(equivalent to the old fork pushingoriginalUrl).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/quicktourlink:/docs/accelerate/quicktour(not/docs/accelerate/main/en/quicktour) ✅svelte-check: 0 errors, prettier clean.🤖 Generated with Claude Code