Fix infinite hydration loop and stabilize global store synchronization

- Refactored layouts to derive account data from stable props instead of reactive stores.
- Wrapped store updates in untrack() with deep equality guards to prevent infinite re-renders.
- Resolved duplicate untrack declarations and missing imports across the project.
- Added fetch safeguards to Element_data_store to prevent redundant API calls.
- Standardized hydration patterns to break circular dependencies during initial load.
This commit is contained in:
Scott Idem
2026-02-08 17:15:20 -05:00
parent 88bc18cf15
commit 718de1457d
33 changed files with 455 additions and 1567 deletions

View File

@@ -9,6 +9,7 @@
let { data, children }: Props = $props();
// *** Import Svelte specific
import { untrack } from 'svelte';
// import { onMount, tick } from 'svelte';
import { goto } from '$app/navigation';
import { sineIn } from 'svelte/easing';
@@ -56,7 +57,9 @@
import Element_websocket_v2 from '$lib/elements/element_websocket_v2.svelte';
// *** Set initial variables
let ae_acct = $derived(data[$slct.account_id]);
// NOTE: Derived from data.account_id (prop) instead of $slct.account_id (store)
// to prevent circular dependency loops during hydration.
let ae_acct = $derived(data[data.account_id]);
import { online } from 'svelte/reactivity/window';
@@ -83,33 +86,41 @@
`event_session_id: ${data.url.searchParams.get('session_id')}`
);
}
$events_slct.event_id = data.params.event_id;
$events_slct.event_location_id = data.params.event_location_id;
$events_slct.event_session_id = data.url.searchParams.get('session_id');
untrack(() => {
$events_slct.event_id = data.params.event_id;
$events_slct.event_location_id = data.params.event_location_id;
$events_slct.event_session_id = data.url.searchParams.get('session_id');
});
});
// String-Only ID Vision: Sync the device ID from the native environment
const native_dev = $derived($ae_loc.native_device);
$effect(() => {
if (native_dev) {
$events_slct.event_device_id =
native_dev.event_device_id ||
native_dev.id ||
native_dev.event_device_id_random ||
native_dev.id_random;
untrack(() => {
$events_slct.event_device_id =
native_dev.event_device_id ||
native_dev.id ||
native_dev.event_device_id_random ||
native_dev.id_random;
});
}
});
$effect(() => {
if (ae_acct) {
$events_slct.event_location_obj_li = ae_acct.slct.event_location_obj_li ?? [
''
];
untrack(() => {
const new_location_obj_li = ae_acct.slct.event_location_obj_li ?? [''];
if (JSON.stringify($events_slct.event_location_obj_li) !== JSON.stringify(new_location_obj_li)) {
$events_slct.event_location_obj_li = new_location_obj_li;
}
const new_id_li__event_location = ae_acct.slct.id_li__event_location ?? [''];
if (JSON.stringify($events_slct.id_li__event_location) !== JSON.stringify(new_id_li__event_location)) {
$events_slct.id_li__event_location = new_id_li__event_location;
}
});
}
});
$events_slct.id_li__event_location = ae_acct.slct.id_li__event_location ?? [
''
];
// *** Functions and Logic

View File

@@ -8,6 +8,7 @@
let log_lvl: number = $state(0);
// Imports
import { untrack } from 'svelte';
import {
ae_snip,
ae_loc,
@@ -37,7 +38,9 @@
// Variables
// Quickly save the data passed from the parent(s) to the Svelte stores, localStorage, and other.
let ae_acct = $derived(data[$slct.account_id]);
// NOTE: Derived from data.account_id (prop) instead of $slct.account_id (store)
// to prevent circular dependency loops during hydration.
let ae_acct = $derived(data[data.account_id]);
// $ae_loc.url_origin = data.url.origin;
@@ -47,27 +50,31 @@
console.log(`event_id: ${data.params.event_id}`);
console.log(`event_location_id: ${data.params.event_location_id}`);
}
$events_slct.event_id = data.params.event_id;
$events_slct.event_location_id = data.params.event_location_id;
untrack(() => {
$events_slct.event_id = data.params.event_id;
$events_slct.event_location_id = data.params.event_location_id;
});
});
$effect(() => {
if (ae_acct) {
$events_slct.event_location_obj_li = ae_acct.slct.event_location_obj_li ?? [
''
];
$events_slct.id_li__event_location = ae_acct.slct.id_li__event_location ?? [
''
];
if (log_lvl) {
console.log(
`$events_slct.event_location_obj_li:`,
$events_slct.event_location_obj_li
);
}
$events_slct.event_session_obj_li = ae_acct.slct.event_session_obj_li ?? [
''
];
untrack(() => {
$events_slct.event_location_obj_li = ae_acct.slct.event_location_obj_li ?? [
''
];
$events_slct.id_li__event_location = ae_acct.slct.id_li__event_location ?? [
''
];
if (log_lvl) {
console.log(
`$events_slct.event_location_obj_li:`,
$events_slct.event_location_obj_li
);
}
$events_slct.event_session_obj_li = ae_acct.slct.event_session_obj_li ?? [
''
];
});
}
});