File tree Expand file tree Collapse file tree
src/lib/components/chat/Messages Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 import { disableSingleTilde } from ' $lib/utils/marked/strikethrough-extension' ;
99 import { mentionExtension } from ' $lib/utils/marked/mention-extension' ;
1010
11+ import { onDestroy } from ' svelte' ;
12+
1113 import MarkdownTokens from ' ./Markdown/MarkdownTokens.svelte' ;
1214 import footnoteExtension from ' $lib/utils/marked/footnote-extension' ;
1315 import citationExtension from ' $lib/utils/marked/citation-extension' ;
5355 ]
5456 });
5557
56- $: (async () => {
57- if (content) {
58- tokens = marked .lexer (
59- replaceTokens (processResponseContent (content), model? .name , $user? .name )
60- );
58+ let rafId = null ;
59+
60+ function lexContent () {
61+ tokens = marked .lexer (
62+ replaceTokens (processResponseContent (content), model? .name , $user? .name )
63+ );
64+ }
65+
66+ // Throttle lexer to once per animation frame while streaming
67+ $: if (content) {
68+ if (done) {
69+ if (rafId) {
70+ cancelAnimationFrame (rafId);
71+ rafId = null ;
72+ }
73+ lexContent ();
74+ } else if (! rafId) {
75+ rafId = requestAnimationFrame (() => {
76+ rafId = null ;
77+ lexContent ();
78+ });
6179 }
62- })();
80+ }
81+
82+ onDestroy (() => {
83+ if (rafId) cancelAnimationFrame (rafId);
84+ });
6385< / script>
6486
6587{#key id}
You can’t perform that action at this time.
0 commit comments