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

JS/React SDKs: Pause SSE subscriptions when tab is hidden #1755

Merged
merged 19 commits into from
Oct 25, 2023

Conversation

bryce-fitzsimons
Copy link
Member

@bryce-fitzsimons bryce-fitzsimons commented Oct 17, 2023

  • Pause SSE on hide, resume on visible
  • Disable this behavior with configureCache option disableIdleStreams: true. Can also configure the idleStreamInterval (default 20 sec).
  • Allow monkeypatching

Features and Changes

  • Closes (add link to issue here)

Dependencies

Testing

Screenshots

@github-actions
Copy link

github-actions bot commented Oct 17, 2023

Your preview environment pr-1755-bttf has been deployed with errors.

@@ -458,24 +500,21 @@ function disableChannel(channel: ScopedChannel) {
channel.src.onerror = null;
channel.src.close();
channel.src = null;
if (channel.state === "active") {
channel.state = "disabled";
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what happens if a channel is disabled while it's in an idle state? Wouldn't it then switch back to active when the page is focused?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (probably) can't happen: we control when a channel gets disabled or idled, and we don't disable anything but active channels. I will add another safeguard just to be sure though...

The reverse can happen though: a disabled channel can be converted to idle, which should be fine given that 99% of the time it's disabled because of some connection error with exponential backoff, and waking up from idle state is a good enough alternative to backoff/retry.

@github-actions
Copy link

github-actions bot commented Oct 25, 2023

Deploy preview for docs ready!

✅ Preview
https://docs-ngtvbs8sk-growthbook.vercel.app

Built with commit 082425f.
This pull request is being automatically deployed with vercel-action

@jdorn jdorn merged commit 7d90658 into main Oct 25, 2023
@jdorn jdorn deleted the sdk-pause-subscriptions-when-hidden branch October 25, 2023 18:38
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.

2 participants