fix(streaming): handle multi-byte UTF-8 chars split across chunks#3083
Merged
waleedlatif1 merged 1 commit intostagingfrom Jan 30, 2026
Merged
fix(streaming): handle multi-byte UTF-8 chars split across chunks#3083waleedlatif1 merged 1 commit intostagingfrom
waleedlatif1 merged 1 commit intostagingfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile OverviewGreptile SummaryThis PR fixes a critical bug where multi-byte UTF-8 characters (Turkish characters, emojis, CJK characters) were being corrupted during SSE streaming when split across HTTP chunk boundaries. Key Changes:
The fix correctly handles both problems:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant readSSEStream
participant TextDecoder
participant Buffer
participant Callbacks
Client->>readSSEStream: body.getReader()
readSSEStream->>TextDecoder: new TextDecoder()
loop For each chunk
readSSEStream->>readSSEStream: reader.read()
alt Chunk received
readSSEStream->>TextDecoder: decode(value, { stream: true })
Note over TextDecoder: Maintains state for<br/>incomplete UTF-8 sequences
TextDecoder-->>Buffer: Decoded text
Buffer->>Buffer: Split by '\n\n'
Buffer->>Buffer: Keep incomplete message
loop For each complete SSE message
Buffer->>Buffer: Extract "data: " content
Buffer->>Buffer: JSON.parse(lineData)
alt Valid chunk
Buffer->>Callbacks: onChunk(data.chunk)
Buffer->>Callbacks: onAccumulated(accumulatedContent)
end
end
else Done
readSSEStream->>TextDecoder: decode()
Note over TextDecoder: Flush any remaining bytes
TextDecoder-->>Buffer: Final text
end
end
readSSEStream-->>Client: accumulatedContent
|
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.
Summary
{ stream: true }to TextDecoder to maintain state across chunksFixes #3068
Type of Change
Testing
Checklist