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

call poll method immediately on focus #202

Merged
merged 1 commit into from May 29, 2021
Merged

Conversation

frbor
Copy link

@frbor frbor commented May 25, 2021

I'm using a large polling interval (~ 10 seconds) for some pages, where the user tends to move to another page, and then come back to check if there is a result.

If I understand the code correctly, moving away from the page will disable polling, and when focusing the page again it will always init the polling with the polling interval before calling the poll function and user then some times executes a manual refresh and sees that there is indeed a result.

Not sure if it applies to all use cases, but I propose to execute the call method immediately on focus.

The code in this PR solves this for my use case, but please give feedback if there are any concerns of problems this might cause.

@adamghill
Copy link
Owner

This makes sense, I think. I wonder if https://github.com/adamghill/django-unicorn/pull/202/files#diff-0511fc9c2567beec4a5e330d5753f7786f7dd495f01c67a89250cafaffc8e02cR333-R339 should be done at the beginning of startPolling since that's effectively what would happen now?

I think when I was testing this before I had a shorter polling time (1 or 2 seconds) so when the tab got re-enabled it would tend to duplicate the poll method. Let me think about and see if I can figure out another approach, but if I can't I'll merge this in and get a new release out in the next few days.

@frbor
Copy link
Author

frbor commented May 26, 2021

I see your point that this code can be moved startPolling, but I guess it depends on how the initial state is loaded.

If the code is moved to startPolling the poll method will always be called immediately after the page is loaded the first time?

In my case the initial state is rendered on the first load (no polling needed), so it is ok to wait for the poll for the update, but others might have it differently.

To sum up I do think it works best (for my current use case) to have the code in addEventListener but I can move it to startPolling if you prefer that.

@adamghill
Copy link
Owner

I created #203 based on this PR. Let me know if that looks ok and I'll make a new release today!

@adamghill adamghill merged commit 9349e33 into adamghill:master May 29, 2021
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.

None yet

2 participants