Skip to content

Commit d87d9b2

Browse files
andrewboldiclaude
andcommitted
fix: use afterUpdate for KaTeX rendering instead of $effect
$effect with tick() wasn't reliably firing after {@html} rendered. afterUpdate runs after every DOM update, ensuring latex images are always replaced with KaTeX. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2f72aa6 commit d87d9b2

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/lib/components/ProblemDisplay.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { afterUpdate } from 'svelte';
23
import { renderLatexInContainer } from '$lib/utils/katex';
34
45
interface Props {
@@ -11,10 +12,9 @@
1112
let { problemId, problemHtml, zenMode, textInvertFilter }: Props = $props();
1213
let container: HTMLElement;
1314
14-
$effect(() => {
15-
if (container && problemHtml) {
16-
// Wait for {@html} to render, then replace latex images
17-
requestAnimationFrame(() => renderLatexInContainer(container));
15+
afterUpdate(() => {
16+
if (container) {
17+
renderLatexInContainer(container);
1818
}
1919
});
2020
</script>

src/lib/components/SolutionDisplay.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts">
2+
import { afterUpdate } from 'svelte';
23
import { renderLatexInContainer } from '$lib/utils/katex';
34
45
interface Props {
@@ -9,9 +10,9 @@
910
let { solutionHtml, textInvertFilter }: Props = $props();
1011
let container: HTMLElement;
1112
12-
$effect(() => {
13-
if (container && solutionHtml) {
14-
requestAnimationFrame(() => renderLatexInContainer(container));
13+
afterUpdate(() => {
14+
if (container) {
15+
renderLatexInContainer(container);
1516
}
1617
});
1718
</script>

0 commit comments

Comments
 (0)