Skip to content

Commit 6863ca4

Browse files
committed
perf: use rAF to debounce getContents() during streaming
1 parent 5645d5b commit 6863ca4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib/components/chat/Chat.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,11 @@
964964
};
965965
966966
$: if (history) {
967-
getContents();
967+
cancelAnimationFrame(contentsRAF);
968+
contentsRAF = requestAnimationFrame(() => {
969+
getContents();
970+
contentsRAF = null;
971+
});
968972
} else {
969973
artifactContents.set([]);
970974
}
@@ -1294,6 +1298,7 @@
12941298
};
12951299
12961300
let scrollRAF = null;
1301+
let contentsRAF = null;
12971302
const scheduleScrollToBottom = () => {
12981303
if (!scrollRAF) {
12991304
scrollRAF = requestAnimationFrame(async () => {

0 commit comments

Comments
 (0)