Skip to content

perf: lazy-load KaTeX via dynamic import of @streamdown/math#8874

Merged
mscolnick merged 2 commits intomainfrom
ms/bundle-size5
Mar 26, 2026
Merged

perf: lazy-load KaTeX via dynamic import of @streamdown/math#8874
mscolnick merged 2 commits intomainfrom
ms/bundle-size5

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

The math plugin for the markdown renderer was statically imported,
pulling katex (~264 KB) into the critical path. Convert to a dynamic
import so katex loads on demand after the first render.

The math plugin for the markdown renderer was statically imported,
pulling katex (~264 KB) into the critical path. Convert to a dynamic
import so katex loads on demand after the first render.
Copilot AI review requested due to automatic review settings March 25, 2026 22:11
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 25, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Mar 25, 2026 11:03pm

Request Review

@mscolnick mscolnick added the enhancement New feature or request label Mar 25, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Bundle Report

Changes will decrease total bundle size by 813.89kB (-3.18%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
marimo-esm 24.78MB -813.89kB (-3.18%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: marimo-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-*.js -28 bytes 618.53kB -0.0%
assets/chunk-*.js -23.85kB 442.35kB -5.11%
assets/edit-*.js -28 bytes 371.54kB -0.01%
assets/index-*.css -6 bytes 360.53kB -0.0%
assets/dist-*.js -7.46kB 11.91kB -38.52%
assets/dist-*.js -4.88kB 19.37kB -20.14%
assets/dist-*.js (New) 24.25kB 24.25kB 100.0% 🚀
assets/add-*.js 52 bytes 55.39kB 0.09%
assets/agent-*.js -28 bytes 158.2kB -0.02%
assets/PTSans-*.woff2 (New) 113.56kB 113.56kB 100.0% 🚀
assets/PTSans-*.woff2 (New) 116.14kB 116.14kB 100.0% 🚀
assets/Lora-*.woff2 (New) 83.69kB 83.69kB 100.0% 🚀
assets/FiraMono-*.woff2 (New) 67.4kB 67.4kB 100.0% 🚀
assets/FiraMono-*.woff2 (New) 62.68kB 62.68kB 100.0% 🚀
assets/FiraMono-*.woff2 (New) 62.3kB 62.3kB 100.0% 🚀
assets/file-*.js -28 bytes 46.84kB -0.06%
assets/chat-*.js -28 bytes 32.37kB -0.09%
assets/react-*.browser.esm-RgA6v8U3.js (New) 25.64kB 25.64kB 100.0% 🚀
assets/session-*.js -28 bytes 25.03kB -0.11%
assets/micromark-*.js (New) 24.12kB 24.12kB 100.0% 🚀
assets/command-*.js -28 bytes 9.81kB -0.28%
assets/run-*.js -28 bytes 10.55kB -0.26%
assets/scratchpad-*.js -28 bytes 8.39kB -0.33%
assets/markdown-*.js -11.72kB 5.3kB -68.87%
assets/mermaid-*.core-BYJHV4Wy.js (New) 2.38kB 2.38kB 100.0% 🚀
assets/PTSans-*.ttf (Deleted) -288.34kB 0 bytes -100.0% 🗑️
assets/PTSans-*.ttf (Deleted) -278.61kB 0 bytes -100.0% 🗑️
assets/Lora-*.ttf (Deleted) -212.0kB 0 bytes -100.0% 🗑️
assets/FiraMono-*.ttf (Deleted) -201.71kB 0 bytes -100.0% 🗑️
assets/FiraMono-*.ttf (Deleted) -169.06kB 0 bytes -100.0% 🗑️
assets/FiraMono-*.ttf (Deleted) -170.2kB 0 bytes -100.0% 🗑️
assets/react-*.browser.esm-DDRqG5ui.js (Deleted) -25.64kB 0 bytes -100.0% 🗑️
assets/mermaid-*.core-CdM8D_p_.js (Deleted) -2.38kB 0 bytes -100.0% 🗑️

Files in assets/markdown-*.js:

  • ./src/components/markdown/markdown-renderer.tsx → Total Size: 6.37kB

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves frontend initial-load performance by deferring the markdown math plugin (and its KaTeX payload) until after the first render, via a dynamic import.

Changes:

  • Removed the static @streamdown/math import from the markdown renderer.
  • Added a useMathPlugin hook with a module-level cache to dynamically load the math plugin on mount.
  • Wired the (possibly-lazy) plugins object into the <Streamdown /> renderer.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

@mscolnick mscolnick merged commit 65860a2 into main Mar 26, 2026
33 checks passed
@mscolnick mscolnick deleted the ms/bundle-size5 branch March 26, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants