perf(ui): hoist marked.use() to module scope to prevent extension stacking (#25837)

This commit is contained in:
G30
2026-06-16 21:09:09 -04:00
committed by GitHub
parent beb9bf60e4
commit b2809e6293

View File

@@ -1,19 +1,41 @@
<script>
import { onDestroy } from 'svelte';
<script context="module">
import { marked } from 'marked';
import { replaceTokens, processResponseContent } from '$lib/utils';
import { user } from '$lib/stores';
import markedExtension from '$lib/utils/marked/extension';
import markedKatexExtension from '$lib/utils/marked/katex-extension';
import { disableSingleTilde } from '$lib/utils/marked/strikethrough-extension';
import { mentionExtension } from '$lib/utils/marked/mention-extension';
import colonFenceExtension from '$lib/utils/marked/colon-fence-extension';
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
import footnoteExtension from '$lib/utils/marked/footnote-extension';
import citationExtension from '$lib/utils/marked/citation-extension';
const options = {
throwOnError: false,
breaks: true
};
marked.use(markedKatexExtension(options));
marked.use(markedExtension(options));
marked.use(citationExtension(options));
marked.use(footnoteExtension(options));
marked.use(colonFenceExtension(options));
marked.use(disableSingleTilde);
marked.use({
extensions: [
mentionExtension({ triggerChar: '@' }),
mentionExtension({ triggerChar: '#' }),
mentionExtension({ triggerChar: '$' })
]
});
</script>
<script>
import { onDestroy } from 'svelte';
import { replaceTokens, processResponseContent } from '$lib/utils';
import { user } from '$lib/stores';
import MarkdownTokens from './Markdown/MarkdownTokens.svelte';
export let id = '';
export let content;
export let done = true;
@@ -41,25 +63,6 @@
let lastContent = '';
let lastParsedContent = '';
const options = {
throwOnError: false,
breaks: true
};
marked.use(markedKatexExtension(options));
marked.use(markedExtension(options));
marked.use(citationExtension(options));
marked.use(footnoteExtension(options));
marked.use(colonFenceExtension(options));
marked.use(disableSingleTilde);
marked.use({
extensions: [
mentionExtension({ triggerChar: '@' }),
mentionExtension({ triggerChar: '#' }),
mentionExtension({ triggerChar: '$' })
]
});
const parseTokens = () => {
if (content === lastContent) return;
lastContent = content;