Skip to content

SMOODEV-2534: fix transient double-newline during streaming#33

Merged
brentrager merged 1 commit into
mainfrom
SMOODEV-2534-streaming-newline-fix
Jul 14, 2026
Merged

SMOODEV-2534: fix transient double-newline during streaming#33
brentrager merged 1 commit into
mainfrom
SMOODEV-2534-streaming-newline-fix

Conversation

@brentrager

Copy link
Copy Markdown
Contributor

Problem

During streaming, the widget briefly showed an extra blank line (a double newline) that disappeared when the message finalized — jarring on every reply. The streamed token render (raw assistant.text += token accumulation) and the finalized render (responseParts.join('\n\n')) were two independent code paths that could disagree on blank-line count mid-stream.

Solution

  • Introduce a shared PARAGRAPH_SEP constant and normalizeParagraphs() (collapses runs of 3+ newlines to a single \n\n), used by BOTH the streaming accumulator and the finalized extractFinalText join.
  • normalizeParagraphs is idempotent and a no-op on well-formed text, so the finalized output stays byte-identical for well-formed responses — only the mid-stream flicker changes.
  • Applied to the interleaved tool-activity text block too, for consistency.

Tests

  • New normalizeParagraphs unit tests (collapse + idempotence/no-op).
  • New streaming integration test: asserts no emitted assistant snapshot (streaming or final) carries a 3+ newline run, the finalized text is byte-identical to responseParts.join('\n\n'), and the last mid-stream render already agrees with the finalized render.
  • Full suite green: 170 tests, typecheck, build all pass.

Release

Patch changeset added (0.14.0 → 0.14.1). The changesets release bot opens the "🦋 New version release" PR; merging it publishes to npm.

🤖 Generated with Claude Code

The streamed token render (raw accumulation) and the finalized render
(responseParts.join) were two independent paths that could disagree on
blank-line count mid-stream, showing an extra blank line that vanished
when the message finalized. Share one PARAGRAPH_SEP + normalizeParagraphs
between both paths so the streaming render matches the finalized render;
the finalized output stays byte-identical for well-formed responses.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b33676d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@smooai/chat-widget Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brentrager brentrager merged commit db9a07a into main Jul 14, 2026
1 check passed
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.

1 participant