fix(sse): emit empty id field to reset Last-Event-ID - #5138
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5138 +/- ##
=======================================
Coverage 79.04% 79.04%
=======================================
Files 154 154
Lines 10779 10779
Branches 2256 2256
=======================================
Hits 8520 8520
Misses 2259 2259 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
yusukebe
approved these changes
Jul 21, 2026
1 task
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
Emit an SSE
idfield whenSSEMessage.idis an empty string.Problem
SSEStreamingApi.writeSSE()currently uses a truthy check when serializingmessage.id:message.id && \id: ${message.id}``This omits the field when
idis an empty string.In Server-Sent Events, an empty
idfield resets the client's last event ID. After the reset, a subsequent reconnect should not send aLast-Event-IDheader.Hono currently cannot express this behavior through
writeSSE().Specification:
https://html.spec.whatwg.org/multipage/server-sent-events.html#the-last-event-id-header
Change
Use an explicit
undefinedcheck:message.id !== undefined && \id: ${message.id}``This preserves the existing behavior when
idis omitted while allowing an empty string to be serialized as an emptyidfield.Test
Added a regression test using:
writeSSE({ data: 'reset', id: '' })The test verifies the exact output:
Local result: