perf: batch history reactive triggers to rAF in chatEventHandler (#22947)

This commit is contained in:
Algorithm5838 authored and GitHub committed 2026-03-24 06:12:37 -05:00
1 parent a9c5c787b9
commit 7ce1e9415a
1 file changed
+15
+15
View File
@@ -536,8 +536,14 @@
console.log('Unknown message type', data); console.log('Unknown message type', data);
} }
if (type === 'chat:message:delta' || type === 'message' || type === 'status') {
scheduleHistoryFlush();
} else {
cancelAnimationFrame(historyRAF);
historyRAF = null;
history.messages[event.message_id] = message; history.messages[event.message_id] = message;
} }
}
} else { } else {
// Non-active chat completion: queue stays in the global store. // Non-active chat completion: queue stays in the global store.
// navigateHandler will process it when the user returns to that chat. // navigateHandler will process it when the user returns to that chat.
@@ -1279,6 +1285,15 @@
let scrollRAF = null; let scrollRAF = null;
let contentsRAF = null; let contentsRAF = null;
let historyRAF = null;
const scheduleHistoryFlush = () => {
if (!historyRAF) {
historyRAF = requestAnimationFrame(() => {
historyRAF = null;
history = history;
});
}
};
const scheduleScrollToBottom = () => { const scheduleScrollToBottom = () => {
if (!scrollRAF) { if (!scrollRAF) {
scrollRAF = requestAnimationFrame(async () => { scrollRAF = requestAnimationFrame(async () => {