Tauri WebView sessions (and long-lived browser tabs) persist hydrated load() data indefinitely, so server-side changes never surface until the user manually navigates across a depends() boundary. Wire visibilitychange + focus to invalidateAll(), throttled to once per 5 min to keep expensive loaders cheap.
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "homepage",
|
||||
"version": "1.44.1",
|
||||
"version": "1.44.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,10 +1,31 @@
|
||||
<script>
|
||||
import '../app.css';
|
||||
import { onNavigate } from '$app/navigation';
|
||||
import { onNavigate, invalidateAll } from '$app/navigation';
|
||||
import { onMount } from 'svelte';
|
||||
import Toast from '$lib/components/Toast.svelte';
|
||||
import ConfirmDialog from '$lib/components/ConfirmDialog.svelte';
|
||||
let { children } = $props();
|
||||
|
||||
/** Refresh server data on resume — Tauri WebView and backgrounded browser tabs
|
||||
* don't re-run SvelteKit load() otherwise. Throttled: at most once per 5 min. */
|
||||
const REFRESH_MIN_GAP_MS = 5 * 60 * 1000;
|
||||
let lastRefreshAt = Date.now();
|
||||
onMount(() => {
|
||||
const refresh = () => {
|
||||
if (document.hidden) return;
|
||||
const now = Date.now();
|
||||
if (now - lastRefreshAt < REFRESH_MIN_GAP_MS) return;
|
||||
lastRefreshAt = now;
|
||||
invalidateAll();
|
||||
};
|
||||
document.addEventListener('visibilitychange', refresh);
|
||||
window.addEventListener('focus', refresh);
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', refresh);
|
||||
window.removeEventListener('focus', refresh);
|
||||
};
|
||||
});
|
||||
|
||||
onNavigate((navigation) => {
|
||||
if (!(/** @type {any} */ (document)).startViewTransition) return;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user