mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-16 11:57:51 +01:00
Merge pull request #17496 from ShirasawaSama/patch-16
feat: Dynamically load katex to improve first-screen loading speed (-630KB)
This commit is contained in:
@@ -1,10 +1,22 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import katex from 'katex';
|
import type { renderToString as katexRenderToString } from 'katex';
|
||||||
import 'katex/contrib/mhchem';
|
import { onMount } from 'svelte';
|
||||||
import 'katex/dist/katex.min.css';
|
|
||||||
|
|
||||||
export let content: string;
|
export let content: string;
|
||||||
export let displayMode: boolean = false;
|
export let displayMode: boolean = false;
|
||||||
|
|
||||||
|
let renderToString: typeof katexRenderToString | null = null;
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
const [katex] = await Promise.all([
|
||||||
|
import('katex'),
|
||||||
|
import('katex/contrib/mhchem'),
|
||||||
|
import('katex/dist/katex.min.css'),
|
||||||
|
]);
|
||||||
|
renderToString = katex.renderToString;
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{@html katex.renderToString(content, { displayMode, throwOnError: false })}
|
{#if renderToString}
|
||||||
|
{@html renderToString(content, { displayMode, throwOnError: false })}
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import katex from 'katex';
|
|
||||||
|
|
||||||
const DELIMITER_LIST = [
|
const DELIMITER_LIST = [
|
||||||
{ left: '$$', right: '$$', display: true },
|
{ left: '$$', right: '$$', display: true },
|
||||||
{ left: '$', right: '$', display: false },
|
{ left: '$', right: '$', display: false },
|
||||||
|
|||||||
Reference in New Issue
Block a user