diff --git a/desktop/src/features/messages/ui/MessageRow.tsx b/desktop/src/features/messages/ui/MessageRow.tsx index ac1cd93991..e253a05c15 100644 --- a/desktop/src/features/messages/ui/MessageRow.tsx +++ b/desktop/src/features/messages/ui/MessageRow.tsx @@ -43,6 +43,10 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip"; const DiffMessage = React.lazy(() => import("./DiffMessage")); const DiffMessageExpanded = React.lazy(() => import("./DiffMessageExpanded")); +/** Stable empty fallback so rows without an agent-pubkey set keep a constant + * reference (a fresh `new Set()` per render would defeat downstream memos). */ +const EMPTY_AGENT_PUBKEYS: ReadonlySet = new Set(); + export type ThreadDepthGuideAction = { active?: boolean; depth: number; @@ -157,17 +161,11 @@ export const MessageRow = React.memo( () => resolveMentionPubkeysByName(message.tags, profiles), [profiles, message.tags], ); - const resolvedAgentPubkeys = React.useMemo(() => { - const pubkeys = new Set(agentPubkeys ?? []); - - for (const [pubkey, profile] of Object.entries(profiles ?? {})) { - if (profile.isAgent) { - pubkeys.add(normalizePubkey(pubkey)); - } - } - - return pubkeys; - }, [agentPubkeys, profiles]); + // The agent-pubkey set is computed once by the parent (ChannelScreen) + // from the same profile lookup and passed down already normalised — no + // per-row rescan of `profiles` (that duplicated the parent's work in every + // mounted row and re-ran on each profile-lookup change). + const resolvedAgentPubkeys = agentPubkeys ?? EMPTY_AGENT_PUBKEYS; const profilePopoverRole = message.role === "bot" || (message.pubkey && diff --git a/desktop/src/features/messages/ui/configNudgeAuthPubkey.ts b/desktop/src/features/messages/ui/configNudgeAuthPubkey.ts index 65582f9650..1866e59040 100644 --- a/desktop/src/features/messages/ui/configNudgeAuthPubkey.ts +++ b/desktop/src/features/messages/ui/configNudgeAuthPubkey.ts @@ -18,7 +18,7 @@ import type { TimelineMessage } from "@/features/messages/types"; */ export function getConfigNudgeAuthorPubkey( message: Pick, - resolvedAgentPubkeys: Set, + resolvedAgentPubkeys: ReadonlySet, ): string | undefined { if ( message.kind === KIND_STREAM_MESSAGE &&