perf(hydration): optimize page loads and silence background fetch noise
- Implemented SWR pattern for Journal and Site Domain lookups. - Refactored +layout.ts across modules to fire background refreshes instead of blocking. - Updated +layout.svelte to render the layout shell immediately while hydrating. - Silenced 'AbortError' and 'NetworkError' in api_get_object.ts and api_post_object.ts for log_lvl 0. - Resolved duplicate export errors in ae_journals__journal.ts.
This commit is contained in:
@@ -1345,6 +1345,17 @@ email = ${$ae_loc?.email}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else if browser && $ae_loc && $ae_loc.allow_access === null}
|
||||
<!-- NEW: Render layout shell while waiting for initial access check -->
|
||||
<div class="min-h-screen flex items-center justify-center">
|
||||
<div class="flex flex-col items-center gap-4">
|
||||
<span class="fas fa-cog fa-spin text-4xl text-primary-500"></span>
|
||||
<div class="text-center">
|
||||
<div class="text-lg font-bold">Initializing Layout...</div>
|
||||
<div class="text-xs opacity-60">Determining access context</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else if browser || flag_reload}
|
||||
<div
|
||||
class="flex flex-col items-center justify-center max-w-lg mx-auto space-y-6 border border-red-500 rounded-lg p-4 bg-green-50 dark:bg-green-900 m-8"
|
||||
|
||||
@@ -4,8 +4,6 @@ console.log(`ae_l_journals [journal_id] +layout.ts start`);
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { browser } from '$app/environment';
|
||||
import { journals_func } from '$lib/ae_journals/ae_journals_functions';
|
||||
// import { db_journals, journal_field_li, journal_entry_field_li } from "$lib/ae_journals/db_journals";
|
||||
// import { load_ae_obj_id } from '$lib/ae_core/core__crud_generic';
|
||||
|
||||
export async function load({ params, parent }) {
|
||||
const log_lvl: number = 0;
|
||||
@@ -36,59 +34,23 @@ export async function load({ params, parent }) {
|
||||
});
|
||||
}
|
||||
ae_acct.slct.journal_id = journal_id;
|
||||
if (log_lvl) {
|
||||
console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
|
||||
}
|
||||
|
||||
if (browser) {
|
||||
if (log_lvl) {
|
||||
console.log(`ae_journals journals [journal_id] +page.ts: journal_id = `, journal_id);
|
||||
}
|
||||
// Load journal object
|
||||
// let load_journal_obj = load_ae_obj_id({
|
||||
// api_cfg: ae_acct.api,
|
||||
// obj_type: 'journal',
|
||||
// obj_id: journal_id,
|
||||
// db_instance: db_journals,
|
||||
// db_field_li: journal_field_li,
|
||||
// inc_obj_type_li: ['journal_entry'],
|
||||
// log_lvl: 2
|
||||
// });
|
||||
if (log_lvl) console.log(`ae_journals journals [journal_id] +layout.ts (Non-Blocking)`);
|
||||
|
||||
const load_journal_obj = await journals_func.load_ae_obj_id__journal({
|
||||
// OPTIMIZATION: Fire the journal load in the background.
|
||||
// The journal module now uses SWR, and components watching IDB
|
||||
// will update automatically when the refresh completes.
|
||||
journals_func.load_ae_obj_id__journal({
|
||||
api_cfg: ae_acct.api,
|
||||
journal_id: journal_id,
|
||||
inc_entry_li: true,
|
||||
enabled: 'enabled',
|
||||
hidden: 'all', // 'not_hidden' to load only visible entries
|
||||
hidden: 'all',
|
||||
limit: 99,
|
||||
try_cache: true,
|
||||
log_lvl: log_lvl
|
||||
log_lvl: 0
|
||||
});
|
||||
// .then((results) => {
|
||||
// if (!results) {
|
||||
// error(404, {
|
||||
// message: 'Journals - Journal not found'
|
||||
// });
|
||||
// } else {
|
||||
// // ae_acct.slct.journal_obj = results;
|
||||
// }
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.error(`Error loading journal object:`, err);
|
||||
// error(500, {
|
||||
// message: 'Journals - Error loading journal object'
|
||||
// });
|
||||
// });
|
||||
|
||||
if (!load_journal_obj) {
|
||||
console.warn(`ae Journals [journal_id] +layout.ts: Journal ${journal_id} not found via API or Cache.`);
|
||||
// error(404, {
|
||||
// message: 'Journals - Journal Entry not found'
|
||||
// });
|
||||
} else {
|
||||
ae_acct.slct.load_journal_obj = load_journal_obj;
|
||||
}
|
||||
}
|
||||
|
||||
// WARNING: Precaution against shared data between sites.
|
||||
|
||||
Reference in New Issue
Block a user