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;
|
// $idaa_slct.post_obj = ae_acct.slct.post_obj;
|
||||||
|
|
||||||
// *** Functions and Logic
|
// *** Functions and Logic
|
||||||
let lq__post_obj = $derived(
|
let lq__post_obj = $derived.by(() => {
|
||||||
liveQuery(async () => {
|
// SVELTE 5 REACTIVITY: Track IDs synchronously
|
||||||
if (log_lvl) {
|
const post_id = $idaa_slct.post_id ?? '';
|
||||||
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
|
|
||||||
|
|
||||||
// Check if results are different than the current $idaa_slct.post_obj
|
return liveQuery(async () => {
|
||||||
if ($idaa_slct.post_obj && results) {
|
if (log_lvl) console.log(`lq__post_obj: post_id = ${post_id}`);
|
||||||
if (JSON.stringify($idaa_slct.post_obj) !== JSON.stringify(results)) {
|
if (!post_id) return null;
|
||||||
$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 results;
|
return await db_posts.post.get(post_id);
|
||||||
})
|
});
|
||||||
);
|
});
|
||||||
|
|
||||||
let lq__post_comment_obj_li = $derived(
|
let lq__post_comment_obj_li = $derived.by(() => {
|
||||||
liveQuery(async () => {
|
const post_id = $idaa_slct.post_id ?? '';
|
||||||
let results = await db_posts.comment
|
const limit = $idaa_loc.bb.qry__limit;
|
||||||
|
|
||||||
|
return liveQuery(async () => {
|
||||||
|
if (!post_id) return [];
|
||||||
|
|
||||||
|
return await db_posts.comment
|
||||||
.where('post_id')
|
.where('post_id')
|
||||||
.equals($idaa_slct.post_id ?? '') // null or undefined does not reset things like '' does
|
.equals(post_id)
|
||||||
.reverse()
|
.reverse()
|
||||||
.limit($idaa_loc.bb.qry__limit)
|
.limit(limit)
|
||||||
.sortBy('tmp_sort_1');
|
.sortBy('tmp_sort_1');
|
||||||
// .sortBy('created_on');
|
});
|
||||||
// .sortBy('updated_on');
|
});
|
||||||
// .sortBy('title');
|
|
||||||
|
|
||||||
if (
|
let lq__post_comment_obj = $derived.by(() => {
|
||||||
$idaa_slct.post_comment_obj_li &&
|
const comment_id = $idaa_slct.post_comment_id ?? '';
|
||||||
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}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
return liveQuery(async () => {
|
||||||
})
|
if (!comment_id) return null;
|
||||||
);
|
return await db_posts.comment.get(comment_id);
|
||||||
|
});
|
||||||
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;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
if (browser) {
|
if (browser) {
|
||||||
console.log('Browser environment detected.');
|
console.log('Browser environment detected.');
|
||||||
|
|||||||
@@ -3,9 +3,10 @@
|
|||||||
lq__post_obj: any;
|
lq__post_obj: any;
|
||||||
lq__post_comment_obj_li: any;
|
lq__post_comment_obj_li: any;
|
||||||
lq__post_comment_obj: 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 Svelte specific
|
||||||
import { browser } from '$app/environment';
|
import { browser } from '$app/environment';
|
||||||
@@ -31,13 +32,17 @@
|
|||||||
|
|
||||||
let ae_promises: key_val = $state({});
|
let ae_promises: key_val = $state({});
|
||||||
|
|
||||||
if ($idaa_slct.post_id) {
|
$effect(() => {
|
||||||
console.log(`Post ID selected: ${$idaa_slct.post_id}`);
|
const post_id = $idaa_slct.post_id;
|
||||||
console.log(`Post Object selected: `, $lq__post_obj);
|
if (post_id) {
|
||||||
console.log(`Post Object title (name): ${$lq__post_obj?.title}`);
|
if (log_lvl) {
|
||||||
|
console.log(`Post ID selected: ${post_id}`);
|
||||||
$idaa_trig.post_id = $idaa_slct.post_id;
|
console.log(`Post Object selected: `, $lq__post_obj);
|
||||||
}
|
}
|
||||||
|
// Trigger background load
|
||||||
|
$idaa_trig.post_id = post_id;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (browser && $lq__post_obj?.post_id) {
|
if (browser && $lq__post_obj?.post_id) {
|
||||||
|
|||||||
Reference in New Issue
Block a user