Skip to content

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

Merged
haydenbleasel merged 5 commits intovercel:mainfrom
sleitor:fix-433
Mar 10, 2026
Merged

fix(streamdown-code): fall back to plain text for unknown/truncated language identifiers#434
haydenbleasel merged 5 commits 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
haydenbleasel and others added 3 commits March 10, 2026 15:54
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`'text'` is a SpecialLanguage in Shiki, not a BundledLanguage, so the
type annotations for getHighlighter and getHighlighterCacheKey need to
accept both.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
streamdown Ready Ready Preview, Comment, Open in v0 Mar 10, 2026 10:59pm

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@haydenbleasel
Copy link
Contributor

great fix @sleitor appreciate it 🚀

@haydenbleasel haydenbleasel merged commit 651873d into vercel:main Mar 10, 2026
3 of 5 checks passed
@sleitor sleitor deleted the fix-433 branch March 11, 2026 00:23
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...

2 participants