Skip to content

Commit 44f8843

Browse files
authored
fix(sse): emit empty id field to reset Last-Event-ID (#5138)
1 parent e36f57d commit 44f8843

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/helper/streaming/sse.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ describe('SSE Streaming helper', () => {
154154
expect(decodedValue).toContain('retry: 0\n\n')
155155
})
156156

157+
it('Should emit an empty id to reset Last-Event-ID', async () => {
158+
const res = streamSSE(c, async (stream) => {
159+
await stream.writeSSE({
160+
data: 'reset',
161+
id: '',
162+
})
163+
})
164+
165+
expect(await res.text()).toBe('data: reset\nid: \n\n')
166+
})
167+
157168
it('Check stream Response if error occurred', async () => {
158169
const onError = vi.fn()
159170
const res = streamSSE(

src/helper/streaming/sse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class SSEStreamingApi extends StreamingApi {
3535
[
3636
message.event && `event: ${message.event}`,
3737
dataLines,
38-
message.id && `id: ${message.id}`,
38+
message.id !== undefined && `id: ${message.id}`,
3939
message.retry !== undefined && `retry: ${message.retry}`,
4040
]
4141
.filter(Boolean)

0 commit comments

Comments
 (0)