Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/genui/lib/src/transport/a2ui_transport_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class A2uiTransportAdapter implements Transport {
Stream<String> get incomingText => _pipeline
.where((e) => e is TextEvent)
.cast<TextEvent>()
.map((e) => e.text.trim())
.where((text) => text.isNotEmpty);
.map((e) => e.text)
.where((text) => text.trim().isNotEmpty);
Comment on lines +68 to +69

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using text.trim().isNotEmpty will discard chunks that consist entirely of whitespace, such as a single space (" ") or a newline ("\n"). In streaming LLM responses, it is extremely common for whitespace or newlines to be emitted as separate chunks. Discarding them will cause words to run together (e.g., producing "Helloworld" instead of "Hello world").

To preserve all valid whitespaces while filtering out truly empty strings, you should use text.isNotEmpty instead of text.trim().isNotEmpty.

Suggested change
.map((e) => e.text)
.where((text) => text.trim().isNotEmpty);
.map((e) => e.text)
.where((text) => text.isNotEmpty);


/// A stream of A2UI messages parsed from the input.
@override
Expand Down