react-native-event-source icon indicating copy to clipboard operation
react-native-event-source copied to clipboard

Same event getting dispatched over and over again

Open superKalo opened this issue 5 years ago • 4 comments

First of all, thanks @jordanbyron for the great work you've done! 👏

I noticed a strange issue on my end. Long story short - the same MessageEvent is getting dispatched via the EventSource over and over again, even though the back-end is not emitting a new message.

Here's the MessageEvent which gets dispatched:

{
  data: "large stringified object with `creationDate` (timestamp) which the server sends"
  lastEventId: ""
  origin: undefined
}

I'm sure that my back-end is not emitting a new message because I also have a web interface where I can test, wired up with the EventSource Web API, where the issue doesn't occur. Moreover the creationDate timestamp in the MessageEvents data I'm receiving from my server and all the other params are absolutely the same.

On my end, this is causing performance issues, because it triggers my sseSource.addEventListener logic I have over and over again every minute or so (there is around 1 min delay until all of the same events get dispatched again, so strange?).

My implementation is quite straight-forward, nothing special I think:

const sseSource = new EventSource(mySseUrl, {
  headers: { Authorization: 'Bearer ' + accessToken },
  withCredentials: false,
});

sseSource.addEventListener('some-event', (response) => console.log(response));

I tend to think that the issue is related to the react-native-event-source implementation, please let me know if you've experienced the same thing? Or if I should search for a problem elsewhere in my application / server implementation?

Edit: Expo SDK v35 (also reproducible on v36), React Native v0.59 (also reproducible on v0.61). Issue arises on iOS and Android both.

superKalo avatar Feb 04 '20 16:02 superKalo

btw, if anyone cares: my workaround is to store the id of each message received... and when a new message kicks in - I double-check first if it is unique or not. Not ideal, I know, but it works.

image

superKalo avatar Feb 06 '20 10:02 superKalo

I’ll be honest I haven’t personally used this library in a while but I do know when I was using it I didn’t have this problem. It would help to know the version of react native your using, what OS (iOS or Android) and if you can reproduce the repeating problem with another server instance.

If you can also provide a working example that I can run that would help resolve the problem as well.

On Feb 6, 2020, at 5:41 AM, Kaloyan Kosev [email protected] wrote:

 btw, if anyone cares: my workaround is to store the id of each message received... and when a new message kicks in - I double-check first if it is unique or not. Not ideal, I know, but it works.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

jordanbyron avatar Feb 06 '20 11:02 jordanbyron

@jordanbyron thanks for your input! I edited the issue with version details. Expo SDK v35 (also reproducible on v36), React Native v0.59 (also reproducible on v0.61). Issue arises on iOS and Android both. I'll see if I can reproduce it on another server instance.

superKalo avatar Feb 06 '20 13:02 superKalo

Same issue with React Native 0.61.5 Android.

felansu avatar Jun 12 '20 11:06 felansu