perf(layers): pause polled refreshes while the tab is hidden

A hidden tab shows nobody the result, so polled layers (flights, quakes,
weather...) skip their refresh while the page is hidden and catch up with
one refresh when it is shown again. The lifecycle takes an optional
pageVisibility service ({ isHidden, subscribe }) so src/data/lifecycle.js
stays free of browser globals; src/app/data.js supplies the document-backed
one. Without the service, refreshes run as before. Every place that stopped
a layer's interval now goes through one helper that also drops the
catch-up listener.

The HUD's 250 ms camera readout also skips hidden tabs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
nu-statsandClaude Opus 5.5 committed 2026-10-23 21:41:33 -04:00
1 parent 8cdd184a90
commit 952671964d
4 files changed
+111 -30

No files matched your search

+9
View File
@@ -14,6 +14,15 @@ export function createApplicationData({
const dataManager = new LayerLifecycle(viewer, {
allowQaRegistration,
getSourceAvailability: catalog?.getSourceAvailability,
// Polled layers skip refreshes while the tab is hidden and catch up
// once when it is shown again.
pageVisibility: {
isHidden: () => document.visibilityState === 'hidden',
subscribe(callback) {
document.addEventListener('visibilitychange', callback);
return () => document.removeEventListener('visibilitychange', callback);
},
},
});
defer(async () => {
await dataManager.destroyAll();