diff --git a/src/lib/elements/element_manage_event_file_li_direct.svelte b/src/lib/elements/element_manage_event_file_li_direct.svelte index a78de042..91b7f85a 100644 --- a/src/lib/elements/element_manage_event_file_li_direct.svelte +++ b/src/lib/elements/element_manage_event_file_li_direct.svelte @@ -21,7 +21,7 @@ }: Props = $props(); import { liveQuery } from 'dexie'; - import { onMount } from 'svelte'; + import { untrack } from 'svelte'; import type { key_val } from '$lib/stores/ae_stores'; import { ae_api } from '$lib/stores/ae_stores'; @@ -44,19 +44,26 @@ // WHY: When a parent page loads with try_cache:false (e.g. presenter detail), // the fresh API data (including event_session_type_code) is NOT written to Dexie. // The liveQuery below then sees stale Dexie records missing that field, so - // the PDF→image convert button condition silently fails. Triggering a try_cache:true - // refresh on mount ensures fresh data is persisted and liveQuery reflects it. - onMount(() => { - if (link_to_id) { + // the PDF→image convert button condition silently fails. + // + // Using $effect (not onMount) because link_to_id arrives AFTER mount when the + // parent presenter liveQuery resolves — onMount fires too early and misses it. + // untrack() prevents the function body's internals from registering as deps. + $effect(() => { + if (!link_to_id) return; + const _id = link_to_id; + const _type = link_to_type; + const _cfg = $ae_api; + untrack(() => { events_func.load_ae_obj_li__event_file({ - api_cfg: $ae_api, - for_obj_type: link_to_type, - for_obj_id: link_to_id, + api_cfg: _cfg, + for_obj_type: _type, + for_obj_id: _id, enabled: 'all', hidden: 'all', try_cache: true }); - } + }); }); let dq__where_val: string = `for_type`;