refac
This commit is contained in:
@@ -99,16 +99,21 @@
|
|||||||
|
|
||||||
// Throttle message list rebuilds to once per animation frame during streaming.
|
// Throttle message list rebuilds to once per animation frame during streaming.
|
||||||
// Structural changes (currentId change) always rebuild immediately.
|
// Structural changes (currentId change) always rebuild immediately.
|
||||||
$: if (history.currentId) {
|
const handleHistoryChange = (currentId, _messages) => {
|
||||||
const currentIdChanged = history.currentId !== lastCurrentId;
|
if (!currentId) {
|
||||||
lastCurrentId = history.currentId;
|
messages = [];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentIdChanged = currentId !== lastCurrentId;
|
||||||
|
lastCurrentId = currentId;
|
||||||
|
|
||||||
if (currentIdChanged) {
|
if (currentIdChanged) {
|
||||||
// Structural change: new chat, navigation, new message — rebuild immediately
|
// Structural change: new chat, navigation, new message — rebuild immediately
|
||||||
cancelAnimationFrame(pendingRebuild);
|
cancelAnimationFrame(pendingRebuild);
|
||||||
pendingRebuild = null;
|
pendingRebuild = null;
|
||||||
buildMessages();
|
buildMessages();
|
||||||
} else if (history.messages) {
|
} else if (_messages) {
|
||||||
// Content update (streaming) — throttle to once per frame
|
// Content update (streaming) — throttle to once per frame
|
||||||
if (!pendingRebuild) {
|
if (!pendingRebuild) {
|
||||||
pendingRebuild = requestAnimationFrame(() => {
|
pendingRebuild = requestAnimationFrame(() => {
|
||||||
@@ -117,9 +122,9 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
messages = [];
|
|
||||||
}
|
$: handleHistoryChange(history.currentId, history.messages);
|
||||||
|
|
||||||
$: if (autoScroll && bottomPadding) {
|
$: if (autoScroll && bottomPadding) {
|
||||||
(async () => {
|
(async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user