Conversation
|
🚀 Cloudflare Workers Preview has been successfully deployed! Preview URL: https://md-pr-1427.doocs.workers.dev Built with commit b6968c3 |
|
🚀 Surge Preview has been successfully deployed! Preview URL: https://doocs-md-preview-pr-1427.surge.sh Built with commit b6968c3 |
There was a problem hiding this comment.
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.mermaidpaths. - 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. |
| import('mermaid') | ||
| .then(mermaid => mermaid.default.render(`mermaid-svg-${cacheKey}`, code)) | ||
| .then((result: { svg: string }) => handleResult(result.svg)) | ||
| .catch(handleError) |
There was a problem hiding this comment.
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().
| 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 }) |
There was a problem hiding this comment.
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.
|
🗑️ Cloudflare Workers preview deployment has been cleaned up. |
No description provided.