fix(streamdown-code): fall back to plain text for unknown/truncated language identifiers#434
Open
sleitor wants to merge 1 commit intovercel:mainfrom
Open
fix(streamdown-code): fall back to plain text for unknown/truncated language identifiers#434sleitor wants to merge 1 commit intovercel:mainfrom
sleitor wants to merge 1 commit intovercel:mainfrom
Conversation
Contributor
|
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
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.
Fixes #433
Problem
When a code block language identifier is network-truncated during streaming (e.g.
rus`` beforerust`` is fully received), Shiki throws:The existing
.catch()handler only logs the error and cleans up subscribers — it doesn't provide a fallbackTokensResult. 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 thelanguageNamesset. If it isn't recognized (truncated or unknown), substitute'text'so Shiki renders the block as plain uncolored text while the stream catches up.All existing tests pass.