Skip to content

fix: Reset event type after empty SSE block - #85

Open
lux-in-tenebris-lucet wants to merge 1 commit into
binaryminds:masterfrom
lux-in-tenebris-lucet:fix/reset-event-type-after-empty-event
Open

fix: Reset event type after empty SSE block#85
lux-in-tenebris-lucet wants to merge 1 commit into
binaryminds:masterfrom
lux-in-tenebris-lucet:fix/reset-event-type-after-empty-event

Conversation

@lux-in-tenebris-lucet

Copy link
Copy Markdown

Summary

  • Reset the buffered event type whenever a blank line ends an SSE block.
  • Add dependency-free Node tests covering named events and the regression.

Problem

The parser currently resets its event type only when the completed block contains data.

For this valid event stream:

event: custom

data: hello

the empty custom block leaves its event type buffered. The following hello event is therefore sent to the custom listener instead of the default message listener.

The SSE parsing algorithm requires the event type buffer to be cleared when a block is dispatched, including when the block contains no data.

User impact

Applications using this stream pattern can silently miss messages because the expected message listener is never called. The data may instead be delivered to an unrelated custom-event listener, potentially causing incorrect application behavior.

This is an uncommon stream shape, but it is valid SSE and should be parsed correctly.

Fix

Move the parser-state reset outside the data check so that every blank-line block boundary clears the buffered data and event type.

Testing

  • Added a control test for a normal named event.
  • Added a regression test for an empty named block followed by a default message.
  • Ran npm test: 2 tests passed.

Related to #14 by adding initial automated parser coverage.

Reset the buffered event type whenever a blank line ends an SSE block, even if no data was collected. This prevents an empty named block from routing the next message to the wrong listener.

Add dependency-free Node tests for named events and the regression.
@lux-in-tenebris-lucet
lux-in-tenebris-lucet marked this pull request as ready for review July 30, 2026 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant