Repository navigation
Draw Mermaid diagrams with Pele, in a worker, as a message arrives - #140
Conversation
Replace the vendored Mermaid.js 11.17.2 (3.57 MB) with Pele 1.10.0 (709 KB), Obsidian's Mermaid renderer. Pele bounds its input and lays out in milliseconds, so a diagram no longer waits for a click: it draws once its message is in, in a message as in a file beside. Pele runs in a worker (diagram-worker.js), so layout never holds the window's thread; a diagram still laying out after 3 s ends the worker. The SVG is held to a million characters, as inserting one that size takes the window about 150 ms. Colors are CSS variables set to the window's, links keep the schemes the window opens, and images are off. A diagram that fails shows Pele's message and is tried again only on a click. Adds app/bench/diagrams.cjs and its numbers in docs/APP.md. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (1)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 919bbfff84
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A diagram draws on its own only while the blocks in the document hold under 2 million characters of drawn SVG; past that it waits for a click. Pele names its IDs from a fixed prefix that each mount renames, so two diagrams' accessible titles never share an ID. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
|
@codex review Round 1 is addressed in 76f818f. Diagrams that draw on their own now stop once the blocks in the document hold 2 million characters of drawn SVG, and later ones wait for a click. Each mount also gets its own IDs. All 214 app tests pass. Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 76f818f861
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
A diagram or chart still queued when its pane was drawn anew, or another agent was opened, is not drawn and its result is not mounted, so the blocks now on screen draw next. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
|
@codex review Round 2 is addressed in 660fb13. A queued drawing whose block has left the document is skipped and never mounted. All 215 app tests pass. Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 660fb13e3a
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
|
@codex review Round 3 is addressed in 0231506 and 19b374e. Drawn blocks that have left the document are now let go on every drawing, clicked or automatic, and every time a pane is drawn. All 215 app tests pass. Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 19b374eb7d
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…d failure Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01Rze6PVuq7A1ENuxrAt6QEA
|
@codex review Generated by Claude Code |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 0941ef0bd3
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
| const lang = (info ?? '').trim().split(/\s+/)[0].toLowerCase(); | ||
| if (draft) return `<div class="rc" data-kind="code">${head(lang, '')}${pre(text, lang)}</div>`; | ||
| if (lang === 'mermaid' || lang === 'mmd') return `<div class="rc" data-kind="mermaid" data-lazy${lazy(page)} data-view="code">${head('mermaid', toggle)}<div class="view"></div>${pre(text, '')}</div>`; | ||
| if (lang === 'mermaid' || lang === 'mmd') return `<div class="rc" data-kind="mermaid" data-lazy data-page data-view="code">${head('mermaid', toggle)}<div class="view"></div>${pre(text, '')}</div>`; |
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Security: Bound automatic diagram rendering
A malicious model, bot, or attached daemon can now make every Mermaid fence render without a click. A 329 KB message with 5,000 distinct block-beta … space:99999 fences passes the provider, Markdown, and transcript bounds; Pele took ~0.6 s per fence locally, below the 3 s timeout, and produced only ~1.2 KB SVG. hydrate() queues all fences while the 2 MiB SVG cap is empty and does not recheck it before worker dispatch, so one reply can burn a worker core for tens of minutes. Cap aggregate automatic render count/work and recheck before dispatch; leave excess diagrams click-to-render.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not fixing this in this PR. It needs a crafted reply with thousands of distinct diagrams, each laid out just under the timeout. The layout runs in the worker, so the window stays responsive. Under the repo's merge rule, hostile-input findings without an ordinary-use bug are logged rather than fixed at merge. This one is in #97, along with the fix: cap the count or total worker time of automatic draws and leave the rest click-to-draw.
Generated by Claude Code
What
The app's
```mermaidblocks (and.mmdfiles beside) now draw with Pele 1.10.0, Obsidian's Mermaid renderer, in place of the vendored Mermaid.js 11.17.2. Mermaid.js is gone; nothing falls back to it.Pele lays out in milliseconds and bounds its input, so a diagram no longer waits for a click on diagram: it draws as soon as its message is in, in a message as in a file. While a reply streams it stays code, as before.
app/ui/diagram-worker.js). One still laying out after 3 s ends the worker, and the next diagram starts another.block-betaspaces. The worker also holds the SVG to a million characters, because inserting a 1.4M-character SVG took the window 183 ms.--pele-*CSS variables set to the window's (app.css), with the series in the charts' order. Labels use the window's font, and the layout fits the block's width.http/https/mailtoand still go through the guarded opener. Images are off, so animg:node fetches nothing.Size: 709 KB (264 KB gzipped), against 3.57 MB (980 KB gzipped) for Mermaid.js.
Measured
node app/bench/diagrams.cjs(new), headless Chrome 153, median of five warm runs, from post to answer:block-betaspace:99999block-betaspace:500000space:1000)The page's longest frame gap while the worker ran was 22 ms. The numbers and what they mean are in docs/APP.md.
Screenshots
A reply's sequence diagram, drawn on arrival (demo mode, Chromium):
PLAN.mdbeside with its flowchart:The real app (Linux build, WebKitGTK webview, playground model). The worker loads from the app's own scheme, and each reply's diagram drew as it came in:
Tests
node --test app/tests/state.test.cjs: 212 pass. The diagram tests now cover:Not yet seen in macOS's WKWebView.