Skip to content
This repository has been archived by the owner on Apr 15, 2023. It is now read-only.

Same event getting dispatched over and over again #27

Open
superKalo opened this issue Feb 4, 2020 · 4 comments
Open

Same event getting dispatched over and over again #27

superKalo opened this issue Feb 4, 2020 · 4 comments

Comments

@superKalo
Copy link

superKalo commented Feb 4, 2020

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
Copy link
Author

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

@jordanbyron
Copy link
Owner

jordanbyron commented Feb 6, 2020 via email

@superKalo
Copy link
Author

@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.

@felansu
Copy link

felansu commented Jun 12, 2020

Same issue with React Native 0.61.5
Android.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants