Skip to content

fix(layout): only reload after a real background period - #301

Open
MasterK0927 wants to merge 1 commit into
developfrom
fix/visibility-reload-develop
Open

MasterK0927 wants to merge 1 commit into
developfrom
fix/visibility-reload-develop

Conversation

@MasterK0927

Copy link
Copy Markdown
Contributor

Note: this is the same one-line fix as #300, which is already merged into feat/av-conferences-new. It's cherry-picked here so develop gets it too. release/1.0 has the same code.

Cause

In ui/src/routes/+layout.svelte, the Doze check works like this:

let lastBackgroundTime = 0;
...
const backgroundDurationMs = now - lastBackgroundTime;
const isLikelyDoze = backgroundDurationMs > 10 * 60 * 1000;

lastBackgroundTime is only set when the page goes hidden. If the page becomes visible without a hidden event first, lastBackgroundTime is still 0. So backgroundDurationMs is Date.now() - 0, about 56 years, the check passes, and the app calls window.location.reload() with no real background period at all.

On desktop this happens whenever the window first opens on another Space or behind other windows: the first time you bring it forward, the app reloads. Anything in memory is lost, including a call in progress. On feat/av-conferences-new it ended a call the moment the user pressed Accept.

Fix

Reload only when there was a real hidden period:

const isLikelyDoze = lastBackgroundTime > 0 && backgroundDurationMs > 10 * 60 * 1000;

The Android Doze case doesn't change: going to the background always fires hidden first, which sets lastBackgroundTime.

Testing

  • Two desktop instances, each window opened on another Space. Before the fix, the first focus reloaded the page. After the fix, there's no reload.
  • Prettier passes.

lastBackgroundTime starts at 0, so the first visibilitychange to visible without an earlier hidden event looked like a long Doze and reloaded the page. On desktop this happens when the window opens on another Space or behind other windows, and the reload ends any call in progress.

This branch has not been deployed

No deployments
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.

1 participant