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

Allow disabling refresh on tab focus #2484

Closed
KaKi87 opened this issue Nov 27, 2023 · 15 comments
Closed

Allow disabling refresh on tab focus #2484

KaKi87 opened this issue Nov 27, 2023 · 15 comments
Assignees
Labels
s: pending triage Pending Triage

Comments

@KaKi87
Copy link
Contributor

KaKi87 commented Nov 27, 2023

Hello,

I often do the following :

  • browse a feed ;
  • open a post in new background tab ;
  • continue browsing feed ;
  • focus post tab.

What I expect is : being able to read the post immediately.

What I experience is : needing to wait for the page to refresh while it already had plenty of time to load in the first place.

Please allow disabling this behavior.

Thanks

@KaKi87 KaKi87 added the s: pending triage Pending Triage label Nov 27, 2023
Copy link

stackblitz bot commented Nov 27, 2023

Solve in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@HawtinZeng
Copy link

Sorry, bro, I don't understand what is your problem, can u give me more explanations or offer some video to demonstrate your problem?

@KaKi87
Copy link
Contributor Author

KaKi87 commented Dec 19, 2023

Exactly like I said :

@KaKi87
Copy link
Contributor Author

KaKi87 commented Mar 6, 2024

Hello,
Any news on this ?
Thanks

@userquin userquin self-assigned this Mar 6, 2024
@userquin
Copy link
Member

userquin commented Mar 6, 2024

I'm going to check the page lifecycle, it seems browsers freeze/discard tabs aggresively or we've a bug in the logic.

We need to control those events to close all indexed db connections and control user account switch:
https://developer.chrome.com/docs/web-platform/page-lifecycle-api

@KaKi87
Copy link
Contributor Author

KaKi87 commented Mar 6, 2024

browsers freeze/discard tabs aggresively

Nope.

or we've a bug

Or a feature. But I just want the ability to disable it.

Thanks

@userquin
Copy link
Member

userquin commented Mar 6, 2024

browsers freeze/discard tabs aggresively

Nope.

From the page lifecycle, Frozen state in the table:

In particular, it's important that you:

  • Close all open IndexedDB connections.
  • Close open BroadcastChannel connections.
  • Close active WebRTC connections.
  • Stop any network polling or close any open Web Socket connections.
  • Release any held Web Locks.

and some more inputs:

For the moment, Chrome is going to be conservative when discarding pages and only do so when it's confident it won't affect users. For example, pages that have been observed to do any of the following while in the hidden state will not be discarded unless under extreme resource constraints:

  • Playing audio
  • Using WebRTC
  • Updating the table title or favicon
  • Showing alerts
  • Sending push notifications

and from unload event, maybe we need to include some protection with the persisted event prop:

const terminationEvent = 'onpagehide' in self ? 'pagehide' : 'unload';
window.addEventListener(terminationEvent, (event) => {
// Note: if the browser is able to cache the page, event.persisted
// is true, and the state is frozen rather than terminated.
});

@KaKi87
Copy link
Contributor Author

KaKi87 commented Mar 6, 2024

I assure you it's none of that.

But in the meantime, I noticed that installing the Disable Page Visibility API extension is a workaround that disables this behavior.

So I went after related listeners and found this :

window.addEventListener('visibilitychange', windowReload, { capture: true })

I'm pretty sure this is it.

@userquin
Copy link
Member

userquin commented Mar 6, 2024

So I went after related listeners and found this :

The listener is added on demand and only when the account changes: keeping both tabs in sync (it is inside a watcher).

This issue seems to be about loading the new page content, the problem here is the tab visibility, there are some useAsyncData forced to reload the data when page is hydrated and reactivated (we've keep alive), I'm checking if we can fix this.

My previous comments was about switching tabs, from time to time there is a page reload, releted to page lifecycle plugin logic, sorry for the noise.

@HawtinZeng
Copy link

HawtinZeng commented Mar 10, 2024

Maybe the refreshed tab is triggered by this hook in [status].vue and index.vue component.

onReactivated(() => {
  // Silently update data when reentering the page
  // The user will see the previous content first, and any changes will be updated to the UI when the request is completed
  refreshStatus()
  refreshContext()
})

@jyn514
Copy link
Contributor

jyn514 commented Sep 26, 2024

The listener is added on demand and only when the account changes: keeping both tabs in sync (it is inside a watcher).

this is not true, it also is added on the first login. i tested and signing out of Elk makes the bug go away (i.e. switching back to the tab becomes instant).

maybe you intended to reload only when the user is changed, not each time the tab gains or loses focus? i can make a PR with that change.

@userquin
Copy link
Member

userquin commented Sep 26, 2024

There is a bug in 0.15.0 version, should be fixed in main elk.zone, we need a new release to fix the page refresh.

@jyn514
Copy link
Contributor

jyn514 commented Sep 26, 2024

There is a bug in 0.15.0 version, should be fixed in main elk.zone, we need a new release to fix the page refresh.

hmm, i am also seeing the bug in my local copy of elk.zone built from 54344ac.

@jyn514
Copy link
Contributor

jyn514 commented Sep 26, 2024

oh i see, you just merged a fix 8 hours ago. yes, with that branch the bug is fixed :) sorry for the noise

@shuuji3
Copy link
Member

shuuji3 commented Sep 26, 2024

We released v0.15.1 and it should be available at https://elk.zone/. The new version includes some reloading issue fixes by #2975.

@shuuji3 shuuji3 closed this as completed Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s: pending triage Pending Triage
Projects
None yet
Development

No branches or pull requests

5 participants