Skip to content

fix(kit): don't crash prerender when a provider/task has no snippet#791

Merged
hanouticelina merged 1 commit into
mainfrom
fix/inference-snippet-resilience
Jun 4, 2026
Merged

fix(kit): don't crash prerender when a provider/task has no snippet#791
hanouticelina merged 1 commit into
mainfrom
fix/inference-snippet-resilience

Conversation

@hanouticelina

Copy link
Copy Markdown
Contributor

Problem

InferenceSnippet.svelte crashes the doc build when an <InferenceSnippet> is rendered for a (provider, task) combo that the kit's bundled @huggingface/inference has no helper for.

snippets.getInferenceSnippets(...) catches the InferenceClientInputError internally and returns [] (it just logs Failed to get provider helper for …). With no snippets:

const languages = [...]            // []
let selectedLanguage = languages[0]; // undefined
const clientsByLanguage = {...};     // {}
$: clients = clientsByLanguage[selectedLanguage];  // undefined
...
{#if clients.length > 1}             // 💥 Cannot read properties of undefined (reading 'length')

That uncaught TypeError becomes a SvelteKit 500 during prerender and fails the entire build.

This is reachable whenever the @huggingface/inference version used to generate the docs is ahead of the version the kit uses to render them. Real example: together + automatic-speech-recognition was added to inference in 4.13.16; docs generated with 4.13.18 include that section, but the kit pins 4.13.15, so the render throws and the build dies.

Fix

Default clients to []:

- 	$: clients = clientsByLanguage[selectedLanguage];
+ 	$: clients = clientsByLanguage[selectedLanguage] ?? [];

The component now renders nothing for an unsupported combo instead of crashing the prerender — making the build resilient to any generator↔renderer version skew.

Verification

Reproduced the exact CI crash condition locally — docs containing the together/ASR section, kit resolving the crashing @huggingface/inference@4.13.15:

  • Without this change: TypeError: Cannot read properties of undefined (reading 'length')Error: 500 /providers/together → build exit 1.
  • With this change: build exit 0, providers/together prerenders successfully, no TypeError. The Failed to get provider helper … line is still logged (harmless — the snippet just renders empty).

Note

This is the minimal, structural safety net. Separately, bumping the kit's @huggingface/inference (currently ^4.13.15, lockfile-pinned to 4.13.15) to a current release would make such sections render their snippet rather than degrade to empty — but that also pulls @huggingface/tasks ^0.20.12^0.21.x, so it's left as a separate maintainer decision.

🤖 Generated with Claude Code

`getInferenceSnippets` returns `[]` for a (provider, task) combo the bundled
`@huggingface/inference` has no helper for (it catches the `InferenceClientInputError`
internally). With no snippets, `selectedLanguage` is undefined, so
`clientsByLanguage[selectedLanguage]` is undefined and `{#if clients.length > 1}`
throws `Cannot read properties of undefined (reading 'length')`, which fails the
whole doc build (SvelteKit 500).

Default `clients` to `[]` so the component renders nothing for an unsupported
combo instead of taking down the build. This makes the prerender resilient to any
skew between the snippet versions used to generate docs vs. render them.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@Wauplin Wauplin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@hanouticelina hanouticelina merged commit bcff59f into main Jun 4, 2026
5 checks passed
@hanouticelina hanouticelina deleted the fix/inference-snippet-resilience branch June 4, 2026 11:00
hanouticelina added a commit to huggingface/hub-docs that referenced this pull request Jun 4, 2026
#791 merged; point both build workflows at the resulting doc-builder main
commit (bcff59f) instead of the fix-branch head.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
hanouticelina added a commit to huggingface/hub-docs that referenced this pull request Jun 4, 2026
…render fix (#2531)

* ci(inference-providers): bump doc-builder pin to InferenceSnippet prerender fix

The inference-providers doc build crashes when a provider/task section has no
snippet in the kit's `@huggingface/inference` (e.g. `together` +
`automatic-speech-recognition`, supported by the generator's 4.13.18 but not the
kit's pinned 4.13.15): the InferenceSnippet component dereferences
`clients.length` on undefined → SvelteKit 500 → build fails on main and every PR.

Bump the pinned doc-builder ref for both build workflows to the fix
(huggingface/doc-builder#791), which defaults `clients` to `[]` so the prerender
no longer crashes on an unsupported combo.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci: repoint doc-builder pin to merged main (huggingface/doc-builder#791)

#791 merged; point both build workflows at the resulting doc-builder main
commit (bcff59f) instead of the fix-branch head.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* ci: bump upload workflow doc-builder pin to bcff59f for consistency

Keep all three inference-providers workflows on the same doc-builder main commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants