Skip to content

fix: durable KaTeX rendering fix — dedupe marked + CSS safety net#505

Merged
tmustier merged 1 commit intomainfrom
fix/katex-rendering-durable
Mar 15, 2026
Merged

fix: durable KaTeX rendering fix — dedupe marked + CSS safety net#505
tmustier merged 1 commit intomainfrom
fix/katex-rendering-durable

Conversation

@tmustier
Copy link
Copy Markdown
Owner

Problem

KaTeX serif/italic font rendering keeps coming back in thinking blocks despite the #486 fix. Formula text with \(...\) patterns renders as math.

Root cause

markdown-block (from @mariozechner/mini-lit) bundles its own marked@16.4.2 while our safety patch targets the root marked@17.0.4. Two separate module instances = our installMarkedSafetyPatch() never intercepts markdown-block's .use() calls.

npm ls marked
├── marked@17.0.4          ← our code patches this ✅
└── mini-lit
    └── marked@16.4.2      ← markdown-block uses this ❌ unpatched

Fix — three-layer defense

Layer Mechanism Protects against
1. Vite dedupe resolve.dedupe: ["marked"] Multiple marked instances — forces all imports to same module
2. CSS safety net markdown-block .katex { font-family: var(--font-sans) !important } Any KaTeX HTML that slips through — won't render as serif
3. Policy (existing) DISABLED_MARKDOWN_EXTENSION_NAMES Extension registration — strips math extensions from .use()

Added a test:models test that verifies the dedupe config stays in vite.config.ts.

Testing

  • npm run build
  • npm run test:models ✅ (19/19, includes new dedupe test)
  • npm run test:security ✅ (45/45)
  • npm run test:context ✅ (640/640)

Root cause: markdown-block (from mini-lit) bundles its own marked@16
while our safety patch targets the root marked@17. Two separate module
instances → our installMarkedSafetyPatch() never intercepts the
markdown-block's .use() calls → KaTeX extensions register freely →
formula text with \(...\) renders as serif italic math.

Three-layer defense:

1. Vite resolve.dedupe for 'marked' — forces all imports to the same
   instance so our safety patch covers markdown-block too. Test added
   to catch removal.

2. CSS safety net — markdown-block .katex, .katex * get forced to
   var(--font-sans) !important. Even if KaTeX somehow renders, it
   won't produce serif/italic text.

3. Policy (existing) — DISABLED_MARKDOWN_EXTENSION_NAMES still strips
   all four math extensions from .use() calls.
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
pi-for-excel Ignored Ignored Mar 15, 2026 10:37pm

@tmustier tmustier merged commit 6187542 into main Mar 15, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant