Files
OSIT-AE-App-Svelte/src/routes/events/[event_id]/+layout.ts
Scott Idem 476ab7ede6 perf(hydration): resolve white page delay by removing blocking awaits from layouts
- Refactored Events root layout to fire load_ae_obj_id__event in the background.
- Refactored Journals list page to fire load_ae_obj_li__journal in the background.
- Combined with SWR module logic, this ensures near-instant UI rendering from Dexie cache while refreshes occur asynchronously.
2026-01-26 17:13:40 -05:00

65 lines
2.0 KiB
TypeScript

/** @type {import('./$types').LayoutLoad} */
console.log(`Events - [event_id] +layout.ts start`);
import { error } from '@sveltejs/kit';
import { browser } from '$app/environment';
import { events_func } from '$lib/ae_events_functions';
export async function load({ params, parent, url }) {
// route
const log_lvl: number = 0;
const data = await parent();
// console.log(`ae events_pres_mgmt event [event_id] +page.ts data:`, data);
data.log_lvl = log_lvl;
const account_id = data.account_id;
let ae_acct = data[account_id];
if (!ae_acct) {
console.warn(`ae Events - [event_id] +layout.ts: Account ${account_id} not found in data. Initializing ghost acct.`);
ae_acct = {
api: data.ae_api || {},
slct: {
account_id: account_id
}
};
}
const event_id = params.event_id;
if (!event_id) {
console.log(
`ae Events - [event_id] +layout.ts: The event_id was not found in the params.event_id!!!`
);
error(404, {
message: 'Events Pres Mgmt - Event ID not found'
});
}
ae_acct.slct.event_id = event_id;
if (browser) {
if (log_lvl) console.log(`ae_events [event_id] +layout.ts (Non-Blocking)`);
// OPTIMIZATION: Fire the event load in the background without 'await'.
// The event module uses SWR, so this will:
// 1. Check Dexie cache and update IDB instantly.
// 2. Fetch fresh data from API and update IDB.
// 3. Components using LiveQuery (like lq__event_obj) will react automatically.
events_func.load_ae_obj_id__event({
api_cfg: ae_acct.api,
event_id: event_id,
inc_file_li: true,
inc_location_li: true,
inc_session_li: true,
inc_template_li: true,
log_lvl: 0 // Keep background quiet unless debugging
});
}
// WARNING: Precaution against shared data between sites and sessions.
data[account_id] = ae_acct;
return data;
}