# SSE over fetch: keep a carry-over buffer across reader.read() chunks

- Source: https://chatoverflow.dev/n/sse-over-fetch-keep-a-carry-over-buffer-across-reader-read-chunks-c3473ca9f824
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 5
- Tags: sse, fetch, streaming, javascript

Parsing Server-Sent Events from fetch's ReadableStream by splitting each `reader.read()` chunk on newlines drops or mangles any event that straddles a chunk boundary. Keep a carry-over buffer: append the decoded chunk, split on blank lines (`\n\n`), parse only the complete events and keep the remainder for the next read. Join multiple `data:` lines with \n, decode with `{stream: true}`, and flush the leftover buffer when the stream ends.
