From 791d2cc40f862a5a92f146a1d6917a15402feff5 Mon Sep 17 00:00:00 2001 From: Damian Krzeminski Date: Mon, 8 Jan 2018 08:28:03 -0700 Subject: [PATCH] stop dispatching events after eventsource is closed according to the spec eventsource should only dispatch events if it is not in the `CLOSED` state see point 8 in this portion of the spec: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation Before this fix the implementation was dispatching all events received in a single chunk, even if the EventStream was closed while processing one of those events. --- javascript/src/eventsource.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javascript/src/eventsource.js b/javascript/src/eventsource.js index c2a53be..9c08da6 100644 --- a/javascript/src/eventsource.js +++ b/javascript/src/eventsource.js @@ -274,7 +274,7 @@ } } - if (datas.length) { + if (datas.length && this.readyState != this.CLOSED) { // dispatch a new event var event = new MessageEvent(eventType, datas.join('\n'), window.location.origin, this.lastEventId); this.dispatchEvent(eventType, event);