Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

perf(native-chat): memoize turn statuses so status-only renders keep transcript slots (STA-6288) (#36141)

Neil52eeb14db330
diff --git a/src/renderer/src/components/native-chat/use-native-chat-turn-status.test.ts b/src/renderer/src/components/native-chat/use-native-chat-turn-status.test.ts
new file mode 100644
index 00000000000..87111ffd0d9
--- /dev/null
+++ b/src/renderer/src/components/native-chat/use-native-chat-turn-status.test.ts
@@ -0,0 +1,30 @@
+// @vitest-environment happy-dom
+
+import { renderHook } from '@testing-library/react'
+import { describe, expect, it } from 'vitest'
+import { useNativeChatTurnStatus } from './use-native-chat-turn-status'
+
+describe('useNativeChatTurnStatus', () => {
+ it('keeps result identity across status-only renders so transcript slots are not rebuilt', () => {
+ const turnKeys = ['turn-1']
+ const settledTurns = new Map([['turn-1', { startedAt: 1, workedSeconds: 5 }]])
+ const { result, rerender } = renderHook(
+ ({ thinking }) =>
+ useNativeChatTurnStatus({
+ turnKeys,
+ liveTurnKey: 'turn-1',
+ isWorking: true,
+ workingStartedAt: 1,
+ settledTurns,
+ thinking
+ }),
+ { initialProps: { thinking: false } }
+ )
+ const first = result.current
+ rerender({ thinking: false })
+ expect(result.current).toBe(first)
+ rerender({ thinking: true })
+ expect(result.current).not.toBe(first)
+ expect(result.current.active?.thinking).toBe(true)
+ })
+})
diff --git a/src/renderer/src/components/native-chat/use-native-chat-turn-status.ts b/src/renderer/src/components/native-chat/use-native-chat-turn-status.ts
index 6bf7f2fdc81..7a050cb7049 100644
--- a/src/renderer/src/components/native-chat/use-native-chat-turn-status.ts
+++ b/src/renderer/src/components/native-chat/use-native-chat-turn-status.ts
@@ -51,11 +51,16 @@ export function useNativeChatTurnStatus({
)
}, [activeTurnKey, isWorking, validTurnKeys, workingStartedAt])
- return selectNativeChatTurnStatuses(timingByTurn, {
- activeTurnKey,
- isWorking,
- workingStartedAt,
- thinking,
- settledByTurn: settledTurns ?? undefined
- })
+ // Stable identity keeps status-only renders from rebuilding transcript slots.
+ return useMemo(
+ () =>
+ selectNativeChatTurnStatuses(timingByTurn, {
+ activeTurnKey,
+ isWorking,
+ workingStartedAt,
+ thinking,
+ settledByTurn: settledTurns ?? undefined
+ }),
+ [timingByTurn, activeTurnKey, isWorking, workingStartedAt, thinking, settledTurns]
+ )
}