-
Notifications
You must be signed in to change notification settings - Fork 234
Description
Bug Description
When using <Streamdown> with the streamdown-code plugin for text streaming, if the model output's code block language identifier gets network-truncated (for instance, the model intends to output rust, but the current chunk only receives the string rus), the internal normalizeLanguage function inside streamdown-code returns this unrecognized/truncated language name "rus" unmodified to the Shiki engine.
Because Shiki cannot find a language package named "rus", it throws an exception:
ShikiError: Language rus is not included in this bundle.
Although this exception is caught by a .catch block in streamdown-code/index.ts which logs a console.error, it does not provide any graceful fallback rendering result (TokensResult), nor does it recover the Promise chain. This leads to an irreversible blockage in the React rendering cycle, causing a Fatal Error in the downstream React component tree (the streaming message bubble) and terminating the rendering of all subsequent streamed text.
To Reproduce
- Import and render
<Streamdown>in a React project, configuringplugins={{ code: codePlugin }}. - Critical Condition: Simulate a slow stream by setting
chunk sizeto1. - Start streaming a Markdown text. When the stream hangs at the truncated identifier
```rus, before the finaltofrustis received. - Observe Console: Immediately throws
[Streamdown Code] Failed to highlight code: ShikiError: Language rus is not included in this bundle. - Observe UI: The React rendering pipeline breaks, resulting in a white screen for that area or a permanent halt in the rendering of that message.
Expected Behavior
The renderer should gracefully fallback to plain text highlighting when it encounters an unknown or truncated language identifier like rus. This ensures the UI remains stable while waiting for the subsequent chunk to complete the identifier (e.g., to rust).
Actual Behavior
When receiving the truncated ```rus, the plugin fails to provide any fallback. It throws an unhandled error, causing the entire message bubble component to crash (blank screen) and preventing any further rendering.
Code Sample
Streamdown Version
Streamdown Version: 2.3.0 (@streamdown/code: 1.0.3)
React Version
18
Node.js Version
No response
Browser(s)
No response
Operating System
None
Additional Context
No response