Skip to content

fix(kit): stop expanding /learn course links to /docs paths on click - #828

Open
sergiopaniego wants to merge 1 commit into
mainfrom
fix-learn-shorthand-links
Open

sergiopaniego wants to merge 1 commit into
mainfrom
fix-learn-shorthand-links

Conversation

@sergiopaniego

Copy link
Copy Markdown
Member

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.svelte rewrites the clicked anchor's pathname in the DOM through getHfDocFullPath ($lib/hfDocPaths.js), which also matched /learn/.... On a course page, a click on /learn/agents-course/unit1/tools becomes /docs/agents-course/main/en/unit1/tools before 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 /docs URL, which is also a 404 for courses:

click /learn/agents-course/unit1/what-are-agents
  -> anchor rewritten to /docs/agents-course/main/en/unit1/what-are-agents
  -> fetch /api/docs/agents-course/main/en/unit1/what-are-agents   404
  -> location = /docs/agents-course/main/en/unit1/what-are-agents  404

Before #792 the same expansion lived inside the svelteKitCustomClient fork and only mutated SvelteKit's internal URL object, never the DOM anchor, so the Hub always saw the original /learn href.

Changes:

  • getHfDocFullPath only expands /docs/... shorthand paths. /learn/... links are left untouched, so the Hub handles them via /api/learn/<course>/<page> as before.

The reroute hook never receives /learn URLs (SvelteKit treats URLs outside base as external before consulting it), so the removed branch was only reachable from the click listener.

Verified on the live agents-course page with fetch/beforeunload instrumented, blocking the anchor pathname write to emulate this change:

before:  fetch /api/docs/agents-course/main/en/unit1/what-are-agents 404, full navigation, Hub 404 page
after:   fetch /api/learn/agents-course/unit1/what-are-agents 200, lands on /learn/agents-course/unit1/what-are-agents

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 from main.

🤖 Generated with Claude Code

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>
@sergiopaniego

Copy link
Copy Markdown
Member Author

@bujji00

bujji00 commented Sep 12, 2026

Copy link
Copy Markdown

I can reproduce this on the live Agents Course:

  1. Open https://huggingface.co/learn/agents-course/en/unit1/thoughts.
  2. Click the bottom-right next-lesson link, “Actions, Enabling the Agent to Engage with Its Environment”.
  3. The anchor initially points to /learn/agents-course/en/unit1/actions, but clicking it requests /api/docs/agents-course/main/en/unit1/actions (404) and navigates to /docs/agents-course/main/en/unit1/actions (404).

Opening https://huggingface.co/learn/agents-course/en/unit1/actions directly works.

This appears to be the same issue addressed by this PR. Thanks for the fix.

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.

5 participants