Skip to content

feat(web): add Mermaid diagram rendering and off-thread KaTeX/Mermaid workers#1226

Merged
wbxl2000 merged 8 commits into
MoonshotAI:mainfrom
Simon-He95:feat/web-mermaid-workers
Jun 30, 2026
Merged

feat(web): add Mermaid diagram rendering and off-thread KaTeX/Mermaid workers#1226
wbxl2000 merged 8 commits into
MoonshotAI:mainfrom
Simon-He95:feat/web-mermaid-workers

Conversation

@Simon-He95

Copy link
Copy Markdown
Contributor

Problem

The web chat currently only supports KaTeX math rendering. Mermaid diagrams (```mermaid` fenced blocks) are not rendered. Additionally, both KaTeX rendering and Mermaid parsing run on the main thread, which can block the UI during live streaming when many diagrams or equations arrive.

What changed

  • Mermaid support: Called enableMermaid() in Markdown.vue to register the default mermaid loader, so markstream-vue's MermaidBlockNode renders fenced mermaid blocks as SVG diagrams.
  • Web Workers: Imported markstream-vue's pre-built workers (katexRenderer.worker, mermaidParser.worker) via Vite's ?worker syntax and registered them with setKaTeXWorker() / setMermaidWorker(). markstream-vue's MathBlockNode and MermaidBlockNode auto-detect the workers and dispatch heavy computation off the main thread, keeping the UI responsive during streaming.
  • worker.format: 'es': Mermaid uses dynamic imports for per-diagram-type code-splitting, which requires ES module worker format; IIFE cannot split chunks.
  • Added mermaid@^11.15.0 to explicit dependencies (was already a peer dep of markstream-vue).

Verification

  • pnpm typecheck — passes
  • pnpm build — passes, worker chunks emitted correctly
  • pnpm test — all 173 tests pass

… workers

Enable Mermaid diagram support in the web chat via markstream-vue's enableMermaid(). Set up Web Workers for both KaTeX rendering and Mermaid parsing using markstream-vue's pre-built workers (katexRenderer.worker, mermaidParser.worker), keeping heavy computation off the main thread during live streaming.
@changeset-bot

changeset-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dfd2715

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2c6e40aee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread apps/kimi-web/src/components/chat/Markdown.vue
…writers

processFileLinks() uses a TreeWalker that scans all text nodes in mdRef.
Mermaid diagrams render as inline SVG, and diagram labels containing
file-path-like strings (e.g. src/App.vue) would be replaced with HTML
<button> elements inside SVG <text> nodes, corrupting the rendered diagram.

processMarkdownLinks() similarly queries a[href] inside SVGs; while
isLocalLink() mostly filters these out, explicitly skipping SVG subtrees
is safer.

Add svg to the closest() exclusion in processFileLinks(), and skip
links inside svg in processMarkdownLinks().
@pkg-pr-new

pkg-pr-new Bot commented Jun 30, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@95ec00a
npx https://pkg.pr.new/@moonshot-ai/kimi-code@95ec00a

commit: 95ec00a

@wbxl2000

Copy link
Copy Markdown
Collaborator

@codex

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 19d819d11d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@wbxl2000

Copy link
Copy Markdown
Collaborator

thanks for your contribution~

@wbxl2000 wbxl2000 merged commit 7f05f58 into MoonshotAI:main Jun 30, 2026
8 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.

2 participants