·12 min read
How to consume SSE and NDJSON streams from fetch without a library
fetch hands you a ReadableStream, so you can parse SSE and NDJSON yourself in about 100 lines. The part everyone gets wrong is cancellation: checking signal.aborted inside your read loop does not stop a stalled stream. I measured it — here is the proof and the fix.