Render paragraph breaks (\n\n) during streaming, not only after#42
Open
infowarrs-tech wants to merge 1 commit into
Open
Render paragraph breaks (\n\n) during streaming, not only after#42infowarrs-tech wants to merge 1 commit into
infowarrs-tech wants to merge 1 commit into
Conversation
The streaming renderer accumulated all assistant output into a single <p> via paraBuf, with processMarkdown turning blank lines into <br> tags. Paragraph spacing therefore only appeared at end-of-stream, when ui.js:finishStreaming swapped the streaming message with a fresh history-rendered version (which splits on /\n\s*\n/ to make real <p> siblings). Mirror that split logic inside updatePara so \n\n in the stream produces real <p> siblings live, making the swap visually invisible. Single newlines continue to render as soft breaks; runs of 3+ newlines collapse to a single split (stray leading whitespace on the new paragraph is stripped). Trailing empty <p>s are still cleaned up by finishStreaming as before. No change to tool/think/code accordion logic.
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.
Problem
I noticed this when using Claude and Mistral, although all LLMs are likely affected. During streaming,
\n\nin model output renders as a<br>inside a single<p>, so paragraph spacing doesn't appear untilfinishStreaminginui.jsswaps the message with a history-rendered version ~500ms after the stream ends. Visible as: paragraph gaps "pop in" at the end of every reply.Cause
updateParaininterfaces/web/static/ui-streaming.jsaccumulates all streamed text intostate.paraBufand writesprocessMarkdown(paraBuf)into a single<p>. The history render atui-parsing.js:renderContentTextsplits on/\n\s*\n/to make real<p>siblings — streaming doesn't.Fix
Mirror the history render's split inside
updatePara. On each update, scanparaBuffor blank-line boundaries; if found, finalize the current<p>, append a new one, and continue. Single newlines remain soft breaks. Runs of 3+ newlines collapse to one split. Trailing empty<p>s are cleaned up by the existing logic infinishStreaming. Tool / think / code accordion handling is untouched.Testing
Verified locally with Claude API and Mistral API. Also tested with a jsdom harness across: single-chunk multi-break, chunk-split-on-boundary, token-by-token streaming, 3+ newlines, whitespace-only blank lines, trailing breaks. All pass.