The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
perf(bot-screen): sidebar group portal keeps one row identity across re-renders
teknium100d819e0c561
diff --git a/apps/desktop/src/plugins/hermes-bots/screen-isolation.test.tsx b/apps/desktop/src/plugins/hermes-bots/screen-isolation.test.tsxindex ffb83505190..00b65c11e8f 100644--- a/apps/desktop/src/plugins/hermes-bots/screen-isolation.test.tsx+++ b/apps/desktop/src/plugins/hermes-bots/screen-isolation.test.tsx@@ -11,7 +11,7 @@ vi.mock('@hermes/plugin-sdk', async () => {Codicon: () => null,useValue: useStore,resolveSiblingWsUrl: vi.fn(),- host: { onEvent: onGatewayEvent, requestProfile: vi.fn() }+ host: { onEvent: vi.fn(onGatewayEvent), requestProfile: vi.fn() }}})vi.mock('./data', async () => {@@ -199,3 +199,16 @@ it('settles on an older backend without display.*: portal tone is unavailable anexpect(view.container.firstChild).toBeNull()view.unmount()})++it('a sidebar group portal keeps its lease subscription across parent re-renders (no per-paint row rebuild)', async () => {+ vi.mocked(host.requestProfile).mockResolvedValue(status)+ const view = render(<ProfileGroupScreenPortal route={{ connectionId: 'host-b', profile: 'default' }} />)+ await act(async () => {})+ const subscriptions = vi.mocked(host.onEvent).mock.calls.length++ view.rerender(<ProfileGroupScreenPortal route={{ connectionId: 'host-b', profile: 'default' }} />)+ view.rerender(<ProfileGroupScreenPortal route={{ connectionId: 'host-b', profile: 'default' }} />)+ await act(async () => {})+ expect(vi.mocked(host.onEvent).mock.calls.length).toBe(subscriptions)+ view.unmount()+})diff --git a/apps/desktop/src/plugins/hermes-bots/screen-portal.tsx b/apps/desktop/src/plugins/hermes-bots/screen-portal.tsxindex 5a050a2abc0..7afa011f243 100644--- a/apps/desktop/src/plugins/hermes-bots/screen-portal.tsx+++ b/apps/desktop/src/plugins/hermes-bots/screen-portal.tsx@@ -12,7 +12,7 @@import { Codicon, host, useValue } from '@hermes/plugin-sdk'import type { RpcEvent } from '@hermes/plugin-sdk'import type { ProfileGroupRoute } from '@hermes/plugin-sdk'-import { useEffect } from 'react'+import { useEffect, useMemo } from 'react'import { $lastRoster } from './data'import { useBots } from './i18n'@@ -168,18 +168,24 @@ export function ScreenPortal({ bot, meta, compact = false }: { bot: RosterRow; m* roster filter still gets its portal (the portal only needs a routable row). */export function ProfileGroupScreenPortal({ route }: { route: ProfileGroupRoute }) {const roster = useValue($lastRoster)+ const { connectionId, profile } = route- const bot =- roster.find(row => {- const resolved = resolveBotConnectionRoute(row)-- return resolved.route- ? resolved.route.profile === route.profile && resolved.route.connectionId === (route.connectionId ?? 'local')- : row.name === route.profile && route.connectionId === null- }) ??- (route.connectionId- ? ({ name: route.profile, sourceScoped: true, connectionId: route.connectionId, connectionKind: route.connectionId === 'local' ? 'local' : 'remote' } as RosterRow)- : ({ name: route.profile } as RosterRow))+ // Stable row identity: the portal's effects key on `bot`, so a synthesized row+ // rebuilt every render would re-subscribe the lease listener on every sidebar paint.+ const bot = useMemo(+ () =>+ roster.find(row => {+ const resolved = resolveBotConnectionRoute(row)++ return resolved.route+ ? resolved.route.profile === profile && resolved.route.connectionId === (connectionId ?? 'local')+ : row.name === profile && connectionId === null+ }) ??+ (connectionId+ ? ({ name: profile, sourceScoped: true, connectionId, connectionKind: connectionId === 'local' ? 'local' : 'remote' } as RosterRow)+ : ({ name: profile } as RosterRow)),+ [connectionId, profile, roster]+ )return <ScreenPortal bot={bot} compact />}