From 23dc34dbbf35b66e99b05ba3acb8480a665dc604 Mon Sep 17 00:00:00 2001 From: thislight Date: Sun, 10 Nov 2024 16:42:37 +0800 Subject: [PATCH] createTimeline: fix the mutate won't work --- src/masto/timelines.ts | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/masto/timelines.ts b/src/masto/timelines.ts index f7bb5a3..19abea7 100644 --- a/src/masto/timelines.ts +++ b/src/masto/timelines.ts @@ -288,20 +288,23 @@ export function createTimeline< } }); - for (const status of chk.chunk) { - const node = untrack(() => lookup.get(status.id))!; - const parent = untrack(() => - status.inReplyToId ? lookup.get(status.inReplyToId) : undefined, - ); - if (parent) { - const children = parent.children ?? []; - if (!children.find((x) => x.value.id == status.id)) { - children.push(node); + untrack(() => { + for (const status of chk.chunk) { + const node = lookup.get(status.id)!; + const parent = status.inReplyToId + ? lookup.get(status.inReplyToId) + : undefined; + + if (parent) { + const children = parent.children ?? []; + if (!children.find((x) => x.value.id == status.id)) { + children.push(node); + } + parent.children = children; + node.parent = parent; } - parent.children = children; - node.parent = parent; } - } + }); const nThreadIds = chk.chunk .filter((x, i) => !existence[i]) @@ -314,9 +317,11 @@ export function createTimeline< setThreads((threads) => [...nThreadIds, ...threads]); } - setThreads((threads) => - threads.filter((id) => (lookup.get(id)!.children?.length ?? 0) === 0), - ); + untrack(() => { + setThreads((threads) => + threads.filter((id) => (lookup.get(id)!.children?.length ?? 0) === 0), + ); + }); }); });