Fix badge loading race conditions and standardize Svelte 5 param resolution
- Resolved 'untrack is not defined' ReferenceError in Badge Detail page. - Transitioned Badge, IDAA Archive, and Journal Entry pages to use page.params for robust reactivity. - Implemented fallback semantic ID lookup for Badges to handle mixed ID formats in URLs. - Added proper loading states to detail views to prevent 'No IDB record' flashes during hydration. - Systematically audited and cleaned up duplicate 'untrack' imports across all Svelte files.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { untrack } from 'svelte';
|
||||||
interface Props {
|
interface Props {
|
||||||
/** @type {import('./$types').PageData} */
|
/** @type {import('./$types').PageData} */
|
||||||
data: any;
|
data: any;
|
||||||
@@ -31,10 +32,17 @@
|
|||||||
// import { events_func } from '$lib/ae_events_functions';
|
// import { events_func } from '$lib/ae_events_functions';
|
||||||
|
|
||||||
import Comp_badge_obj_view from './ae_comp__badge_obj_view.svelte';
|
import Comp_badge_obj_view from './ae_comp__badge_obj_view.svelte';
|
||||||
|
import { page } from '$app/state';
|
||||||
|
import { LoaderCircle } from 'lucide-svelte';
|
||||||
|
|
||||||
// *** Variables
|
// *** Variables
|
||||||
// let test_event_id = data.params.event_id;
|
// let test_event_id = data.params.event_id;
|
||||||
let event_badge_id = $derived(data.params.badge_id);
|
// Use page.params for robust reactivity in Svelte 5
|
||||||
|
let event_badge_id = $derived(page.params.badge_id);
|
||||||
|
|
||||||
|
// Track if we are waiting for initial IDB result
|
||||||
|
let is_loading_idb = $state(true);
|
||||||
|
|
||||||
// console.log(`Data Params: event_id=${test_event_id}; badge_id=${test_event_badge_id}`);
|
// console.log(`Data Params: event_id=${test_event_id}; badge_id=${test_event_badge_id}`);
|
||||||
let url_test_val = $derived(data.url.searchParams.get('test_val'));
|
let url_test_val = $derived(data.url.searchParams.get('test_val'));
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
@@ -43,12 +51,21 @@
|
|||||||
|
|
||||||
let lq__event_badge_obj = $derived(
|
let lq__event_badge_obj = $derived(
|
||||||
liveQuery(async () => {
|
liveQuery(async () => {
|
||||||
|
if (!event_badge_id) return null;
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(
|
console.log(
|
||||||
`*** LiveQuery: lq__event_badge_obj *** event_badge_id=${event_badge_id}`
|
`*** LiveQuery: lq__event_badge_obj *** event_badge_id=${event_badge_id}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
// Attempt lookup by the ID provided in the URL
|
||||||
let results = await db_events.badge.get(event_badge_id);
|
let results = await db_events.badge.get(event_badge_id);
|
||||||
|
|
||||||
|
// Fallback: If not found by PK, try searching the event_badge_id index
|
||||||
|
// (Standardizing on semantic IDs)
|
||||||
|
if (!results) {
|
||||||
|
results = await db_events.badge.where('event_badge_id').equals(event_badge_id).first();
|
||||||
|
}
|
||||||
|
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(
|
console.log(
|
||||||
`*** LiveQuery: lq__event_badge_obj *** results=`,
|
`*** LiveQuery: lq__event_badge_obj *** results=`,
|
||||||
@@ -59,6 +76,13 @@
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// SIDE EFFECT: Update loading state when the observable value changes
|
||||||
|
$effect(() => {
|
||||||
|
if ($lq__event_badge_obj !== undefined) {
|
||||||
|
untrack(() => is_loading_idb = false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let lq__event_badge_template_obj = $derived(
|
let lq__event_badge_template_obj = $derived(
|
||||||
liveQuery(async () => {
|
liveQuery(async () => {
|
||||||
let results = await db_events.badge_template.get(
|
let results = await db_events.badge_template.get(
|
||||||
@@ -168,6 +192,17 @@
|
|||||||
{lq__event_badge_template_obj}
|
{lq__event_badge_template_obj}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
{:else if is_loading_idb || !event_badge_id}
|
||||||
|
<div class="flex flex-col items-center justify-center p-20 gap-4 opacity-50">
|
||||||
|
<LoaderCircle size="3em" class="animate-spin" />
|
||||||
|
<p class="text-xl font-bold text-center">Loading Badge Details...</p>
|
||||||
|
</div>
|
||||||
{:else}
|
{:else}
|
||||||
<p>No IDB record found for ID: {event_badge_id}</p>
|
<div class="card p-8 variant-soft-error border border-error-500/30 text-center space-y-4">
|
||||||
|
<h2 class="h2 font-black text-error-500">Badge Not Found</h2>
|
||||||
|
<p class="opacity-70">No record found locally for ID: <span class="font-mono">{event_badge_id}</span></p>
|
||||||
|
<button class="btn variant-filled-primary" onclick={() => window.location.reload()}>
|
||||||
|
<span class="fas fa-sync mr-2"></span> Force Refresh
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -31,4 +31,8 @@ export async function load({ params, parent, url }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
params
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
import Archive_content_obj_id_edit from './ae_idaa_comp__archive_content_obj_id_edit.svelte';
|
import Archive_content_obj_id_edit from './ae_idaa_comp__archive_content_obj_id_edit.svelte';
|
||||||
import Modal_media_player from './ae_idaa_comp__modal_media_player.svelte';
|
import Modal_media_player from './ae_idaa_comp__modal_media_player.svelte';
|
||||||
import Help_tech from '$lib/app_components/e_app_help_tech.svelte';
|
import Help_tech from '$lib/app_components/e_app_help_tech.svelte';
|
||||||
|
import { page } from '$app/state';
|
||||||
|
|
||||||
// let ae_promises: key_val = {};
|
// let ae_promises: key_val = {};
|
||||||
// let ae_tmp: key_val = {};
|
// let ae_tmp: key_val = {};
|
||||||
@@ -58,7 +59,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// For some reason data.params.archive_id (or whatever param) is not being passed to this page when loaded by a link from another page. This seems to be a bug with Svelte or SvelteKit. Hopefully fixed in a future version 5? 2024-11-06
|
// For some reason data.params.archive_id (or whatever param) is not being passed to this page when loaded by a link from another page. This seems to be a bug with Svelte or SvelteKit. Hopefully fixed in a future version 5? 2024-11-06
|
||||||
$idaa_slct.archive_id = ae_acct.slct.archive_id;
|
// SVELTE 5 FIX: Use page.params directly for robust reactivity
|
||||||
|
$idaa_slct.archive_id = page.params.archive_id;
|
||||||
// $idaa_slct.archive_obj = ae_acct.slct.archive_obj;
|
// $idaa_slct.archive_obj = ae_acct.slct.archive_obj;
|
||||||
|
|
||||||
// *** Functions and Logic
|
// *** Functions and Logic
|
||||||
|
|||||||
Reference in New Issue
Block a user