From 74242f45a4e0edfcfd7c8ea2c8a363c7c6966aa9 Mon Sep 17 00:00:00 2001 From: llama Date: Sat, 5 Jul 2025 19:49:12 +0800 Subject: [PATCH] debounce mathjax rendering via cooldown instead --- ts/editable/Mathjax.svelte | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/ts/editable/Mathjax.svelte b/ts/editable/Mathjax.svelte index bc8e5cf81..74fbbba43 100644 --- a/ts/editable/Mathjax.svelte +++ b/ts/editable/Mathjax.svelte @@ -38,7 +38,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { pageTheme } from "$lib/sveltelib/theme"; import { convertMathjax, unescapeSomeEntities } from "./mathjax"; - import { ChangeTimer } from "./change-timer"; + import { CooldownTimer } from "./cooldown-timer"; export let mathjax: string; export let block: boolean; @@ -46,25 +46,23 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html let converted: string, title: string; - const debouncedMathjax = writable(mathjax); - const debouncer = new ChangeTimer(); - $: debouncer.schedule(() => debouncedMathjax.set(mathjax), 500); + const debouncer = new CooldownTimer(500); - $: { + $: debouncer.schedule(() => { const cache = getCache($pageTheme.isDark, fontSize); - const entry = cache.get($debouncedMathjax); + const entry = cache.get(mathjax); if (entry) { [converted, title] = entry; } else { const entry = convertMathjax( - unescapeSomeEntities($debouncedMathjax), + unescapeSomeEntities(mathjax), $pageTheme.isDark, fontSize, ); [converted, title] = entry; - cache.set($debouncedMathjax, entry); + cache.set(mathjax, entry); } - } + }); $: empty = title === "MathJax"; $: encoded = encodeURIComponent(converted);