diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index d4fb9bfb..7912d0c3 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -2,7 +2,7 @@ /** @type {import('./$types').LayoutData} */ // /** @type {import('./$types').LayoutProps} */ - let log_lvl: number = 1; + let log_lvl: number = 0; // *** Import Svelte specific import { untrack } from 'svelte'; @@ -71,6 +71,20 @@ let last_reload_time = 0; + // Shallow equality guard — avoids triggering Svelte store updates when the merged + // object is functionally identical to the current one. Comparing JSON.stringify on + // large objects like $ae_loc (site config, device info, flags) is expensive and + // runs on every navigation. Key-by-key identity check is O(n keys), not O(n chars). + function shallow_equal(a: Record, b: Record): boolean { + const keys_a = Object.keys(a); + const keys_b = Object.keys(b); + if (keys_a.length !== keys_b.length) return false; + for (const k of keys_a) { + if (a[k] !== b[k]) return false; + } + return true; + } + // 1. CONSOLIDATED SYNC EFFECT (One single point of entry for store updates) $effect(() => { if (!browser || !ae_acct) return; @@ -83,7 +97,7 @@ const new_api = { ...current_api, ...(ae_acct.api || {}) }; // Deep check for JWT specifically to avoid extra triggers if (current_api.jwt !== $ae_loc.jwt) new_api.jwt = $ae_loc.jwt; - if (JSON.stringify(current_api) !== JSON.stringify(new_api)) { + if (!shallow_equal(current_api, new_api)) { $ae_api = new_api; } @@ -93,13 +107,13 @@ if (!new_loc.sys_menu) new_loc.sys_menu = { hide: false, hide_access_type: false, expand_access_type: false, hide_edit_mode: false, expand_edit_mode: false, hide_user: false, expand_user: false, hide_theme: false, expand_theme: false, hide_cfg: false, expand_cfg: false }; if (!new_loc.debug_menu) new_loc.debug_menu = { hide: false, expand: false }; - if (JSON.stringify(current_loc) !== JSON.stringify(new_loc)) { + if (!shallow_equal(current_loc, new_loc)) { $ae_loc = new_loc; } const current_slct = $slct; const new_slct = { ...current_slct, ...(ae_acct.slct || {}) }; - if (JSON.stringify(current_slct) !== JSON.stringify(new_slct)) { + if (!shallow_equal(current_slct, new_slct)) { $slct = new_slct; } diff --git a/src/routes/events/[event_id]/(launcher)/launcher/+layout.svelte b/src/routes/events/[event_id]/(launcher)/launcher/+layout.svelte index d1c6714f..554f56d1 100644 --- a/src/routes/events/[event_id]/(launcher)/launcher/+layout.svelte +++ b/src/routes/events/[event_id]/(launcher)/launcher/+layout.svelte @@ -1,5 +1,5 @@