Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate connections to SSE with useEventSource regardless of the event #281

Merged
merged 1 commit into from
Nov 25, 2023

Conversation

na2hiro
Copy link
Contributor

@na2hiro na2hiro commented Nov 25, 2023

use-event-source has a feature to deduplicate SSE connections in order to lower the number of EventStreams a browser needs to hold. However, when event name is the only differences, it creates multiple identical EventStreams and then on client side it listens to different events.

Instead, we can create a single EventStream for the same URL and withCredentials flag, no matter what event is.

Example

Given code like these

  const pinged = !!useEventSource(`/events`, { event: "ping" });
  const users = useEventSource(`/events`, { event: "users" });

It creates identical event streams

duplicate-sse-connections

after

Screenshot 2023-11-25 at 9 44 04

@sergiodxa sergiodxa added the enhancement New feature or request label Nov 25, 2023
@sergiodxa sergiodxa changed the title [use-event-source] Deduplicate connections to SSE with different events Deduplicate connections to SSE with useEventSource regardless of the event Nov 25, 2023
@sergiodxa sergiodxa merged commit 651b16c into sergiodxa:main Nov 25, 2023
@sergiodxa
Copy link
Owner

Released on v7.3.0

@na2hiro na2hiro deleted the deduplicate-sse-connections branch November 25, 2023 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants