perf: reduce chat rerenders during streaming

Stabilizes unchanged chat turns while messages stream
Keeps static chat history from rerendering unnecessarily
Adds coverage for turn record reuse
This commit is contained in:
Bohdan Triapitsyn
2026-05-27 14:01:25 +03:00
parent 27255c642d
commit cfd13544bd
4 changed files with 113 additions and 12 deletions
@@ -22,9 +22,14 @@ export const useTurnRecords = (
const staticTurnsRef = React.useRef<TurnRecord[]>([]);
const streamingTurnRef = React.useRef<TurnRecord | undefined>(undefined);
const previousSessionKeyRef = React.useRef<string | undefined>(options.sessionKey);
const previousShowTextJustificationActivityRef = React.useRef(options.showTextJustificationActivity);
if (previousSessionKeyRef.current !== options.sessionKey) {
if (
previousSessionKeyRef.current !== options.sessionKey
|| previousShowTextJustificationActivityRef.current !== options.showTextJustificationActivity
) {
previousSessionKeyRef.current = options.sessionKey;
previousShowTextJustificationActivityRef.current = options.showTextJustificationActivity;
previousProjectionRef.current = null;
staticTurnsRef.current = [];
streamingTurnRef.current = undefined;