From 4690548946dbe31e7cbc127f559315534c2112b8 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Wed, 11 Mar 2026 13:43:33 -0400 Subject: [PATCH] =?UTF-8?q?fix(events):=20switch=20onMount=E2=86=92\$effec?= =?UTF-8?q?t=20for=20file=20list=20Dexie=20refresh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit onMount fired before the parent presenter liveQuery resolved, so link_to_id was undefined and the refresh was silently skipped. Using \$effect makes the background refresh re-run once link_to_id becomes available (after the presenter Dexie lookup completes), ensuring event_session_type_code is written to Dexie and the PDF→image convert button renders correctly. Co-Authored-By: Claude Sonnet 4.6 --- ...element_manage_event_file_li_direct.svelte | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) 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`;