Skip to content

fix(streamdown-code): fall back to plain text for unknown/truncated language identifiers#434

Open
sleitor wants to merge 1 commit intovercel:mainfrom
sleitor:fix-433
Open

fix(streamdown-code): fall back to plain text for unknown/truncated language identifiers#434
sleitor wants to merge 1 commit intovercel:mainfrom
sleitor:fix-433

Conversation

@sleitor
Copy link
Contributor

@sleitor sleitor commented Mar 6, 2026

Fixes #433

Problem

When a code block language identifier is network-truncated during streaming (e.g. rus`` before rust`` is fully received), Shiki throws:

ShikiError: Language rus is not included in this bundle.

The existing .catch() handler only logs the error and cleans up subscribers — it doesn't provide a fallback TokensResult. This leaves the render callback hanging, causing the React component tree to crash (blank screen).

Fix

Before calling getHighlighter(), check whether the resolved language name is in the languageNames set. If it isn't recognized (truncated or unknown), substitute 'text' so Shiki renders the block as plain uncolored text while the stream catches up.

const safeLang = languageNames.has(resolvedLanguage as BundledLanguage)
  ? (resolvedLanguage as BundledLanguage)
  : ('text' as BundledLanguage);

All existing tests pass.

@vercel
Copy link
Contributor

vercel bot commented Mar 6, 2026

Someone is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

…anguage identifiers

When a code block's language identifier is unrecognised by Shiki (e.g.
'rus' from a network-truncated 'rust'), createHighlighter throws a
ShikiError. Previously the .catch() block only logged the error and
left subscribers hanging, causing a permanent React render-cycle stall.

Fix: resolve the language to the 'text' fallback *before* calling
getHighlighter() when the identifier is not in the bundledLanguages
set. This prevents the exception entirely and ensures the code block
renders with plain-text highlighting instead of breaking.

Fixes vercel#433
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.

I want to report a bug...

1 participant