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.
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
/** @type {import('./$types').LayoutLoad} */
|
||||
console.log(`Events - [event_id] launcher +layout.ts start`);
|
||||
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';
|
||||
import type { ae_Event } from '$lib/types/ae_types';
|
||||
|
||||
export async function load({ params, parent, url }) {
|
||||
// route
|
||||
@@ -30,7 +29,7 @@ export async function load({ params, parent, url }) {
|
||||
const event_id = params.event_id;
|
||||
if (!event_id) {
|
||||
console.log(
|
||||
`ae Events - [event_id] +page.ts: The event_id was not found in the params.event_id!!!`
|
||||
`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'
|
||||
@@ -40,42 +39,22 @@ export async function load({ params, parent, url }) {
|
||||
ae_acct.slct.event_id = event_id;
|
||||
|
||||
if (browser) {
|
||||
// console.log(`TEST URL Params`, params);
|
||||
// console.log(`TEST URL`, url);
|
||||
if (log_lvl) console.log(`ae_events [event_id] +layout.ts (Non-Blocking)`);
|
||||
|
||||
const load_event_obj: ae_Event | null = await events_func.load_ae_obj_id__event({
|
||||
// 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_device_li: true,
|
||||
inc_location_li: true,
|
||||
inc_session_li: true,
|
||||
// inc_badge_li: true,
|
||||
inc_template_li: true,
|
||||
log_lvl: log_lvl
|
||||
// })
|
||||
// .then((results) => {
|
||||
// if (!results) {
|
||||
// error(404, {
|
||||
// message: 'Events - Event not found'
|
||||
// });
|
||||
// } else {
|
||||
// // ae_acct.slct.event_obj = results;
|
||||
// }
|
||||
log_lvl: 0 // Keep background quiet unless debugging
|
||||
});
|
||||
if (!load_event_obj) {
|
||||
console.warn(`Events - [event_id] +layout.ts: Event ${event_id} not found via API or Cache.`);
|
||||
// error(404, {
|
||||
// message: 'Events - Event not found'
|
||||
// });
|
||||
} else {
|
||||
console.log(`load_event_obj = `, load_event_obj);
|
||||
ae_acct.slct.event_obj = load_event_obj;
|
||||
// ae_acct.slct.event_device_obj_li = load_event_obj.event_device_obj_li;
|
||||
ae_acct.slct.event_location_obj_li = load_event_obj.event_location_obj_li;
|
||||
ae_acct.slct.event_session_obj_li = load_event_obj.event_session_obj_li;
|
||||
ae_acct.slct.badge_template_obj_li = load_event_obj.event_badge_template_obj_li;
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING: Precaution against shared data between sites and sessions.
|
||||
|
||||
@@ -24,37 +24,15 @@ export async function load({ fetch, parent }) {
|
||||
};
|
||||
}
|
||||
|
||||
const journal_id = ae_acct.slct.journal_id; // From root +layout.ts
|
||||
if (!journal_id) {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`INFO: journals +layout.ts: The journal_id was not found in the parent_data.`
|
||||
);
|
||||
}
|
||||
// return false;
|
||||
}
|
||||
|
||||
if (browser) {
|
||||
if (journal_id) {
|
||||
// let ae_params = {};
|
||||
if (log_lvl) console.log(`ae_journals +page.ts (Non-Blocking)`);
|
||||
|
||||
const load_journal_obj_li = journals_func.load_ae_obj_id__journal({
|
||||
api_cfg: ae_acct.api,
|
||||
journal_id: journal_id,
|
||||
hidden: 'all', // 'not_hidden' to load only visible entries
|
||||
// params: ae_params,
|
||||
try_cache: true,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
ae_acct.slct.journal_obj_li = load_journal_obj_li;
|
||||
}
|
||||
|
||||
// console.log(`ae_acct = `, ae_acct);
|
||||
// WARNING: This does not currently work because the person_id has not been set yet.
|
||||
const person_id = ae_acct.loc.person_id;
|
||||
// console.log(`person_id = `, person_id);
|
||||
|
||||
const load_journal_obj_li = await journals_func.load_ae_obj_li__journal({
|
||||
// OPTIMIZATION: Fire the journal list load in the background.
|
||||
// Components using LiveQuery (db_journals) will display cached data
|
||||
// instantly while this refresh runs.
|
||||
journals_func.load_ae_obj_li__journal({
|
||||
api_cfg: ae_acct.api,
|
||||
for_obj_type: 'account',
|
||||
for_obj_id: account_id,
|
||||
@@ -62,13 +40,10 @@ export async function load({ fetch, parent }) {
|
||||
inc_entry_li: true,
|
||||
hidden: 'all', // 'not_hidden'
|
||||
enabled: 'enabled',
|
||||
// order_by_li: {'priority': 'DESC', 'sort': 'DESC', 'name': 'ASC', 'updated_on': 'DESC', 'created_on': 'DESC'},
|
||||
limit: 25,
|
||||
// params: ae_params,
|
||||
try_cache: true,
|
||||
log_lvl: log_lvl
|
||||
log_lvl: 0
|
||||
});
|
||||
ae_acct.slct.journal_obj_li = load_journal_obj_li;
|
||||
}
|
||||
|
||||
parent_data[account_id] = ae_acct;
|
||||
|
||||
Reference in New Issue
Block a user