fix(idaa): resolve infinite loop and ReferenceError in BB post view
- Deleted redundant reactive trigger in post view component. - Removed state-syncing side-effects from liveQuery derivation. - Standardized log_lvl prop to resolve initialization crash. - Optimized performance for single post loading.
This commit is contained in:
@@ -52,91 +52,42 @@
|
||||
// $idaa_slct.post_obj = ae_acct.slct.post_obj;
|
||||
|
||||
// *** Functions and Logic
|
||||
let lq__post_obj = $derived(
|
||||
liveQuery(async () => {
|
||||
if (log_lvl) {
|
||||
console.log(`lq__post_obj: post_id = ${$idaa_slct?.post_id}`);
|
||||
}
|
||||
let results = await db_posts.post.get($idaa_slct.post_id ?? ''); // null or undefined does not reset things like '' does
|
||||
let lq__post_obj = $derived.by(() => {
|
||||
// SVELTE 5 REACTIVITY: Track IDs synchronously
|
||||
const post_id = $idaa_slct.post_id ?? '';
|
||||
|
||||
// Check if results are different than the current $idaa_slct.post_obj
|
||||
if ($idaa_slct.post_obj && results) {
|
||||
if (JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(results)) {
|
||||
$idaa_slct.post_obj = { ...results };
|
||||
if (log_lvl) {
|
||||
console.log(`$idaa_slct.post_obj = `, $idaa_slct.post_obj);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`Post object has not changed for post_id: ${$idaa_slct.post_id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return liveQuery(async () => {
|
||||
if (log_lvl) console.log(`lq__post_obj: post_id = ${post_id}`);
|
||||
if (!post_id) return null;
|
||||
|
||||
return results;
|
||||
})
|
||||
);
|
||||
return await db_posts.post.get(post_id);
|
||||
});
|
||||
});
|
||||
|
||||
let lq__post_comment_obj_li = $derived(
|
||||
liveQuery(async () => {
|
||||
let results = await db_posts.comment
|
||||
let lq__post_comment_obj_li = $derived.by(() => {
|
||||
const post_id = $idaa_slct.post_id ?? '';
|
||||
const limit = $idaa_loc.bb.qry__limit;
|
||||
|
||||
return liveQuery(async () => {
|
||||
if (!post_id) return [];
|
||||
|
||||
return await db_posts.comment
|
||||
.where('post_id')
|
||||
.equals($idaa_slct.post_id ?? '') // null or undefined does not reset things like '' does
|
||||
.equals(post_id)
|
||||
.reverse()
|
||||
.limit($idaa_loc.bb.qry__limit)
|
||||
.limit(limit)
|
||||
.sortBy('tmp_sort_1');
|
||||
// .sortBy('created_on');
|
||||
// .sortBy('updated_on');
|
||||
// .sortBy('title');
|
||||
});
|
||||
});
|
||||
|
||||
if (
|
||||
$idaa_slct.post_comment_obj_li &&
|
||||
JSON.stringify($idaa_slct.post_comment_obj_li) !== JSON.stringify(results)
|
||||
) {
|
||||
$idaa_slct.post_comment_obj_li = [...results];
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`$idaa_slct.post_comment_obj_li = `,
|
||||
$idaa_slct.post_comment_obj_li
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`Post comment object list has not changed for post_id: ${$idaa_slct.post_id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
let lq__post_comment_obj = $derived.by(() => {
|
||||
const comment_id = $idaa_slct.post_comment_id ?? '';
|
||||
|
||||
return results;
|
||||
})
|
||||
);
|
||||
|
||||
let lq__post_comment_obj = $derived(
|
||||
liveQuery(async () => {
|
||||
let results = await db_posts.comment.get($idaa_slct.post_comment_id ?? ''); // null or undefined does not reset things like '' does
|
||||
|
||||
// Check if results are different than the current $idaa_slct.post_comment_obj
|
||||
if ($idaa_slct.post_comment_obj && results) {
|
||||
if (JSON.stringify($idaa_slct.post_comment_obj) !== JSON.stringify(results)) {
|
||||
$idaa_slct.post_comment_obj = { ...results };
|
||||
if (log_lvl) {
|
||||
console.log(`$idaa_slct.post_comment_obj = `, $idaa_slct.post_comment_obj);
|
||||
}
|
||||
} else {
|
||||
if (log_lvl) {
|
||||
console.log(
|
||||
`Post comment object has not changed for post_comment_id: ${$idaa_slct.post_comment_id}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
})
|
||||
);
|
||||
return liveQuery(async () => {
|
||||
if (!comment_id) return null;
|
||||
return await db_posts.comment.get(comment_id);
|
||||
});
|
||||
});
|
||||
|
||||
if (browser) {
|
||||
console.log('Browser environment detected.');
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
lq__post_obj: any;
|
||||
lq__post_comment_obj_li: any;
|
||||
lq__post_comment_obj: any;
|
||||
log_lvl?: number;
|
||||
}
|
||||
|
||||
let { lq__post_obj, lq__post_comment_obj_li, lq__post_comment_obj }: Props = $props();
|
||||
let { lq__post_obj, lq__post_comment_obj_li, lq__post_comment_obj, log_lvl = 0 }: Props = $props();
|
||||
|
||||
// *** Import Svelte specific
|
||||
import { browser } from '$app/environment';
|
||||
@@ -31,13 +32,17 @@
|
||||
|
||||
let ae_promises: key_val = $state({});
|
||||
|
||||
if ($idaa_slct.post_id) {
|
||||
console.log(`Post ID selected: ${$idaa_slct.post_id}`);
|
||||
console.log(`Post Object selected: `, $lq__post_obj);
|
||||
console.log(`Post Object title (name): ${$lq__post_obj?.title}`);
|
||||
|
||||
$idaa_trig.post_id = $idaa_slct.post_id;
|
||||
}
|
||||
$effect(() => {
|
||||
const post_id = $idaa_slct.post_id;
|
||||
if (post_id) {
|
||||
if (log_lvl) {
|
||||
console.log(`Post ID selected: ${post_id}`);
|
||||
console.log(`Post Object selected: `, $lq__post_obj);
|
||||
}
|
||||
// Trigger background load
|
||||
$idaa_trig.post_id = post_id;
|
||||
}
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (browser && $lq__post_obj?.post_id) {
|
||||
|
||||
Reference in New Issue
Block a user