mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-27 17:58:07 +00:00
perf(desktop): keep thread message component types stable across a session switch
This commit is contained in:
parent
825069004a
commit
bbfe181a2a
1 changed files with 18 additions and 11 deletions
|
|
@ -77,9 +77,21 @@ export const Thread: FC<{
|
|||
// deps. Only their definedness stays a dep — it gates UI (the user
|
||||
// Stop button, the restore-confirm affordance). Assigned during render
|
||||
// (the useStoreSelector pattern) so the ref never lags a render.
|
||||
//
|
||||
// cwd / gateway / sessionId ride the same ref for the same reason, and it
|
||||
// is load-bearing on the hot path: all three change on EVERY session
|
||||
// switch, so listing them as deps re-minted these types mid-switch and
|
||||
// remounted the entire OUTGOING transcript — thousands of renders of a
|
||||
// thread that was about to be replaced, all of it before the resume RPC
|
||||
// had even been sent. They are read inside the edit composer (which only
|
||||
// exists while a message is being edited), never during a plain render,
|
||||
// so a ref read is always current by the time it matters.
|
||||
const callbacksRef = useRef({ onBranchInNewChat, onCancel, onDismissError, onRestoreToMessage })
|
||||
callbacksRef.current = { onBranchInNewChat, onCancel, onDismissError, onRestoreToMessage }
|
||||
|
||||
const editContextRef = useRef({ cwd, gateway, sessionId })
|
||||
editContextRef.current = { cwd, gateway, sessionId }
|
||||
|
||||
const hasBranchInNewChat = Boolean(onBranchInNewChat)
|
||||
const hasCancel = Boolean(onCancel)
|
||||
const hasDismissError = Boolean(onDismissError)
|
||||
|
|
@ -96,7 +108,11 @@ export const Thread: FC<{
|
|||
/>
|
||||
),
|
||||
SystemMessage,
|
||||
UserEditComposer: () => <UserEditComposer cwd={cwd} gateway={gateway} sessionId={sessionId} />,
|
||||
UserEditComposer: () => {
|
||||
const { cwd: editCwd, gateway: editGateway, sessionId: editSessionId } = editContextRef.current
|
||||
|
||||
return <UserEditComposer cwd={editCwd} gateway={editGateway} sessionId={editSessionId} />
|
||||
},
|
||||
UserMessage: () => (
|
||||
<UserMessage
|
||||
onCancel={hasCancel ? () => callbacksRef.current.onCancel?.() : undefined}
|
||||
|
|
@ -104,16 +120,7 @@ export const Thread: FC<{
|
|||
/>
|
||||
)
|
||||
}),
|
||||
[
|
||||
cwd,
|
||||
gateway,
|
||||
hasBranchInNewChat,
|
||||
hasCancel,
|
||||
hasDismissError,
|
||||
hasRestoreToMessage,
|
||||
requestRestoreConfirm,
|
||||
sessionId
|
||||
]
|
||||
[hasBranchInNewChat, hasCancel, hasDismissError, hasRestoreToMessage, requestRestoreConfirm]
|
||||
)
|
||||
|
||||
const emptyPlaceholder = intro ? (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue