fix(kit): stop expanding /learn course links to /docs paths on click - #828
Open
sergiopaniego wants to merge 1 commit into
Open
fix(kit): stop expanding /learn course links to /docs paths on click#828sergiopaniego wants to merge 1 commit into
sergiopaniego wants to merge 1 commit into
Conversation
Since #792 the shorthand-link canonicalizer in +layout.svelte rewrites the clicked anchor's pathname in the DOM. For course pages served at hf.co/learn/<course>/... it turned /learn/agents-course/unit1/tools into /docs/agents-course/main/en/unit1/tools before the Hub's own link handler read it, so the Hub fetched /api/docs/agents-course/main/en/unit1/tools (404, courses live under /api/learn/) and fell back to a full navigation to the /docs URL, which is also a 404 for courses. Only agents-course was rebuilt with the new kit so far (2026-09-09) and every sidebar / next-page click there ends on a 404 (agents-course#736, #737). Leaving /learn links untouched restores the previous behavior: the Hub handles them via /api/learn/<course>/<page>. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Member
Author
|
reported here: https://x.com/piyushJha__/status/2097967836027371782 :) |
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 does this PR do?
Fixes in-page navigation on course pages served at
hf.co/learn/...when built with the current kit. On huggingface/agents-course, rebuilt on 2026-09-09 (first course rebuilt since the Svelte 5 migration), every sidebar and next-page click ends on a 404: huggingface/agents-course#736, huggingface/agents-course#737.Since #794 the click listener in
+layout.svelterewrites the clicked anchor'spathnamein the DOM throughgetHfDocFullPath($lib/hfDocPaths.js), which also matched/learn/.... On a course page, a click on/learn/agents-course/unit1/toolsbecomes/docs/agents-course/main/en/unit1/toolsbefore the Hub's own link handler reads it. The Hub then fetches/api/docs/agents-course/main/en/unit1/tools, which is a 404 (courses are only served under/api/learn/<course>/<page>), and falls back to a full navigation to the/docsURL, which is also a 404 for courses:Before #792 the same expansion lived inside the
svelteKitCustomClientfork and only mutated SvelteKit's internal URL object, never the DOM anchor, so the Hub always saw the original/learnhref.Changes:
getHfDocFullPathonly expands/docs/...shorthand paths./learn/...links are left untouched, so the Hub handles them via/api/learn/<course>/<page>as before.The
reroutehook never receives/learnURLs (SvelteKit treats URLs outsidebaseas external before consulting it), so the removed branch was only reachable from the click listener.Verified on the live agents-course page with
fetch/beforeunloadinstrumented, blocking the anchorpathnamewrite to emulate this change:and the helper itself with node:
/learn/agents-course/unit1/tools->undefined,/docs/agents-course/unit1/tools->/docs/agents-course/main/en/unit1/tools,/docs/trl/quickstart(other library) ->undefined. Prettier clean.kit/has no JS test runner, so there is no unit test to add here without pulling in one.Only agents-course is affected today. Every other course's bucket is still on a pre-#792 build, and each will break the same way on its first rebuild until this lands. After merging, agents-course needs a rebuild (re-run
build_documentation.yml) to pick up the fixed kit, no agents-course-side change needed since the reusable workflow checks out doc-builder frommain.🤖 Generated with Claude Code