Skip to content

Commit a4afe8c

Browse files
committed
fix: extract stable identity pairs for prewarm effect to avoid re-runs on thread summary changes
The prewarmedSidebarThreads memo depended on sidebarThreadByKey, which is recreated whenever any sidebar thread summary changes. Since the useEffect only needs environmentId and threadId (stable identities), this caused unnecessary cleanup/re-setup cycles for all prewarm subscriptions on every thread status update. Replace the thread-object lookup with parseScopedThreadKey to extract identity pairs directly from the already-stable prewarmedSidebarThreadKeys, breaking the dependency on the frequently-changing sidebarThreadByKey map. Applied via @cursor push command
1 parent 9284b86 commit a4afe8c

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
type GitStatusResult,
4444
} from "@t3tools/contracts";
4545
import {
46+
parseScopedThreadKey,
4647
scopedProjectKey,
4748
scopedThreadKey,
4849
scopeProjectRef,
@@ -2884,26 +2885,26 @@ export default function Sidebar() {
28842885
() => getSidebarThreadIdsToPrewarm(visibleSidebarThreadKeys),
28852886
[visibleSidebarThreadKeys],
28862887
);
2887-
const prewarmedSidebarThreads = useMemo(
2888+
const prewarmedSidebarThreadRefs = useMemo(
28882889
() =>
28892890
prewarmedSidebarThreadKeys.flatMap((threadKey) => {
2890-
const thread = sidebarThreadByKey.get(threadKey);
2891-
return thread ? [thread] : [];
2891+
const ref = parseScopedThreadKey(threadKey);
2892+
return ref ? [ref] : [];
28922893
}),
2893-
[prewarmedSidebarThreadKeys, sidebarThreadByKey],
2894+
[prewarmedSidebarThreadKeys],
28942895
);
28952896

28962897
useEffect(() => {
2897-
const releases = prewarmedSidebarThreads.map((thread) =>
2898-
retainThreadDetailSubscription(thread.environmentId, thread.id),
2898+
const releases = prewarmedSidebarThreadRefs.map((ref) =>
2899+
retainThreadDetailSubscription(ref.environmentId, ref.threadId),
28992900
);
29002901

29012902
return () => {
29022903
for (const release of releases) {
29032904
release();
29042905
}
29052906
};
2906-
}, [prewarmedSidebarThreads]);
2907+
}, [prewarmedSidebarThreadRefs]);
29072908

29082909
useEffect(() => {
29092910
const clearThreadJumpHints = () => {

0 commit comments

Comments
 (0)