Skip to content

chore: remove cdn for mermaid lib#1427

Merged
yanglbme merged 3 commits intomainfrom
chore/mermaid
Apr 1, 2026
Merged

chore: remove cdn for mermaid lib#1427
yanglbme merged 3 commits intomainfrom
chore/mermaid

Conversation

@yanglbme
Copy link
Copy Markdown
Member

@yanglbme yanglbme commented Apr 1, 2026

No description provided.

Copilot AI review requested due to automatic review settings April 1, 2026 12:55
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🚀 Cloudflare Workers Preview has been successfully deployed!

Preview URL: https://md-pr-1427.doocs.workers.dev

Built with commit b6968c3

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🚀 Surge Preview has been successfully deployed!

Preview URL: https://doocs-md-preview-pr-1427.surge.sh

Built with commit b6968c3

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 removes the external Mermaid CDN dependency and switches the app/core to always load Mermaid from the installed mermaid package, aligning Mermaid rendering with the bundled build pipeline.

Changes:

  • Removed Mermaid CDN script usage and related global window.mermaid paths.
  • Updated Mermaid initialization and rendering to rely on dynamic import('mermaid').
  • Updated Vite Rollup config to stop externalizing Mermaid so it can be bundled.

Reviewed changes

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

File Description
packages/core/src/utils/initializeMermaid.ts Simplifies Mermaid initialization to always dynamically import Mermaid.
packages/core/src/extensions/mermaid.ts Removes global Mermaid usage and always dynamically imports Mermaid for rendering.
apps/web/vite.config.ts Stops treating Mermaid as an external/global so it’s bundled.
apps/web/index.html Removes the Mermaid CDN <script> tag.

Comment on lines +31 to +34
import('mermaid')
.then(mermaid => mermaid.default.render(`mermaid-svg-${cacheKey}`, code))
.then((result: { svg: string }) => handleResult(result.svg))
.catch(handleError)
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

After removing the CDN/global Mermaid, renderMermaid() can now call mermaid.default.render() before initializeMermaid() has finished importing + initializing Mermaid (main.ts triggers initialization but does not await it). This can lead to rendering with default config or initialization-order failures. Consider centralizing Mermaid loading/initialization behind a shared promise (e.g., getMermaid() that imports + initializes once) and have renderMermaid() await that before calling render().

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +3
export async function initializeMermaid() {
// 优先使用全局 CDN 的 mermaid
if (typeof window !== `undefined` && (window as any).mermaid) {
const mermaid = (window as any).mermaid
mermaid.initialize({ startOnLoad: false })
}
else {
// 回退到动态导入(开发环境)
const mermaid = await import(`mermaid`)
mermaid.default.initialize({ startOnLoad: false })
}
const mermaid = await import(`mermaid`)
mermaid.default.initialize({ startOnLoad: false })
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

initializeMermaid() currently imports and initializes Mermaid on every call, but the Mermaid extension separately imports Mermaid to render diagrams. To avoid duplicated logic and to fix init/render ordering, consider memoizing the import+initialize in this module (e.g., module-level initPromise) and reusing it from the renderer so Mermaid is initialized exactly once before any render() calls.

Copilot uses AI. Check for mistakes.
@yanglbme yanglbme merged commit 9d87aa9 into main Apr 1, 2026
2 checks passed
@yanglbme yanglbme deleted the chore/mermaid branch April 1, 2026 23:54
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 1, 2026

🗑️ Cloudflare Workers preview deployment has been cleaned up.

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