Compare commits

..

No commits in common. "b19e5ac3d47240f9e34e93a5f55b83d38851fcfb" and "51069ae05a223d20303fbb051dace3f445ed980b" have entirely different histories.

3 changed files with 5 additions and 55 deletions

View File

@ -681,11 +681,6 @@ class ServicesManager {
for (const [name] of this.openLogStreams) this._closeLogStream(name); for (const [name] of this.openLogStreams) this._closeLogStream(name);
} }
// Public hook for the page lifecycle (pagehide). Closes every live log
// tail so the browser can BFCache-snapshot the page instead of being
// forced into a full reload on back/forward.
pauseStreams() { this._stopAllLogs(); }
// ------------------------------------------------------------------ // ------------------------------------------------------------------
// Status refresh loop (only updates dots/text, not full re-render) // Status refresh loop (only updates dots/text, not full re-render)
// ------------------------------------------------------------------ // ------------------------------------------------------------------

View File

@ -170,14 +170,6 @@ class LibrePortalSPAClean {
// Update browser history // Update browser history
if (addToHistory) { if (addToHistory) {
history.pushState({ route: path }, '', path); history.pushState({ route: path }, '', path);
} else {
// Even for "don't add to history" navigations (initial route, back-compat
// rewrites) we stamp the current entry's state with the resolved route.
// Without this the very first history entry has state: null, so popstate
// back to it from a later pushState'd entry hits the null guard and
// does nothing — exactly the "back button doesn't work" symptom.
const here = window.location.pathname + window.location.search;
history.replaceState({ route: path }, '', here);
} }
this.currentRoute = path; this.currentRoute = path;
@ -381,7 +373,7 @@ class LibrePortalSPAClean {
const taskId = url.searchParams.get('task'); const taskId = url.searchParams.get('task');
const canonical = window.appPath(appName, tab, sub, taskId); const canonical = window.appPath(appName, tab, sub, taskId);
if (canonical !== url.pathname + url.search) { if (canonical !== url.pathname + url.search) {
window.history.replaceState({ route: canonical }, '', canonical); window.history.replaceState({}, '', canonical);
} }
} }
@ -620,36 +612,11 @@ window.navigateToRoute = function(href) {
} }
}; };
// Handle browser back/forward. Prefer the route stamped on the history // Handle browser back/forward
// entry's state; fall back to the URL bar so entries that somehow lack
// state (third-party history manipulation, very-early popstate before
// init() finished) still re-render the right page instead of no-op'ing.
window.addEventListener('popstate', (e) => { window.addEventListener('popstate', (e) => {
if (!window.spaClean) return; if (e.state && e.state.route && window.spaClean) {
const route = (e.state && e.state.route) || (window.location.pathname + window.location.search); window.spaClean.navigate(e.state.route, false);
window.spaClean.navigate(route, false); }
});
// Back-forward cache (BFCache) cooperation. Open SSE/WebSocket connections
// block the browser from snapshotting the page, so the back button ends up
// doing a full reload instead of restoring instantly. Closing every live
// bus we own on pagehide lets the snapshot happen; on pageshow with
// event.persisted === true the page just came back from BFCache and we
// reopen them. Fresh loads also fire pageshow but with persisted=false —
// we ignore those because the normal init paths already started everything.
window.addEventListener('pagehide', () => {
try { window.taskEventBus && window.taskEventBus.stop(); } catch (_) {}
try { window.LiveSystem && window.LiveSystem.pause && window.LiveSystem.pause(); } catch (_) {}
try { window.servicesManager && window.servicesManager.pauseStreams && window.servicesManager.pauseStreams(); } catch (_) {}
});
window.addEventListener('pageshow', (e) => {
if (!e.persisted) return;
try { window.taskEventBus && window.taskEventBus.start(); } catch (_) {}
try { window.LiveSystem && window.LiveSystem.resume && window.LiveSystem.resume(); } catch (_) {}
// Service log tail streams aren't auto-resumed — the user can click
// Resume on the overlay if they were tailing a log. Most BFCache restores
// are "back to dashboard", so silently dropping the tail is fine.
}); });
// Handle internal link clicks // Handle internal link clicks

View File

@ -105,18 +105,6 @@ window.LiveSystem = (() => {
// Fetch the last sample synchronously (or null if the stream hasn't // Fetch the last sample synchronously (or null if the stream hasn't
// produced one yet). Useful for snapshot-style reads without a sub. // produced one yet). Useful for snapshot-style reads without a sub.
get last() { return last; }, get last() { return last; },
// Force-close the stream and cancel any pending reopen. Used by the
// page lifecycle (pagehide) so the browser can put the page into
// BFCache; the visibilitychange handler would normally do this too,
// but firing explicitly leaves nothing to race.
pause() {
close();
if (reopenTimer) { clearTimeout(reopenTimer); reopenTimer = null; }
},
// Reopen if anything is still subscribed and the document is visible.
// Called from pageshow(persisted=true) when the page is restored from
// BFCache.
resume() { open(); },
// Test hook: count of active subscribers. // Test hook: count of active subscribers.
get subCount() { return subs.size; } get subCount() { return subs.size; }
}; };