Skip to content

feat(plugins): swimlane edges routed with libavoid from the CDN (1.3.1) - #123

Merged
alderg merged 10 commits into
mainfrom
voice/mermaid-libavoid
Nov 18, 2026
Merged

alderg merged 10 commits into
mainfrom
voice/mermaid-libavoid

Conversation

@alderg

@alderg alderg commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Replaces #122. That pull request was stacked on #120's branch, and GitHub closed it when that branch was deleted after #120's merge. A closed pull request's base can't be changed, so this one carries on with the same branch against main. #122 has the reviews, and all their threads are resolved. The branch now has main merged in (merge commit, no force-push): #120 is in main as one squash commit, and this diff shows only this change.

What

jgraph/drawio-mermaid#20 routes the edges of a swimlane-beta diagram around its shapes with the host's libavoid (globalThis.Avoid and AvoidRouting). The plugins' scripts/mermaid-to-drawio.js (added in #120) now loads libavoid as draw.io does, js/libavoid-js/libavoid.min.js and then libavoid-routing.js from viewer.diagrams.net, once its bundles have loaded.

  • Both files are optional and load in an evaluate of their own: they are fetched together and run, in their order, only when both have arrived within 20 s. Otherwise neither runs and the diagram converts as it does today. So a slow libavoid never fails the conversion, and a late one never runs between two diagrams of one run.
  • The app server's viewer already loads the two files before drawio-mermaid, so nothing changes there.
  • Plugin version 1.3.1 in every manifest and in .github/plugin/marketplace.json.
  • plugins/claude-code/DEVELOPING.md keeps main's Sandbox bullet (from Mermaid in, editable draw.io out: every type checked, plugins convert without draw.io Desktop #120's last commit) next to this change's libavoid, Swimlanes and Tests text.

The routing only takes effect once a draw.io release ships the drawio-mermaid build with routing. The CDN's drawio-mermaid has none yet, and drawio-mcp has no copy of its own to update. Until then this change loads libavoid, and conversion stays as it is.

Test

mcp-app-server/test/mermaid-swimlane-routing.test.js converts Mermaid's swimlane example through a local mirror of the CDN:

  • The script requests the viewer's LIBAVOID_FILES after drawio-mermaid.
  • With libavoid answered 404, it still converts the same shapes. With libavoid sent later than it waits, it converts the same diagram.
  • libavoid sent too late is never in the page, even after it has arrived. libavoid that arrives in time is in the page (globalThis.Avoid and AvoidRouting).
  • With a drawio-mermaid that routes (set MERMAID_PATH, or the CDN's once draw.io ships it), no edge in the script's or the viewer's result runs through a shape. Without routing, "Pay" to "Raise invoice" runs through "Pick items".

App server suite after the merge with main: 355 pass, 0 fail. 6 skips: the two routing checks (the CDN's drawio-mermaid doesn't route yet) and four that need things this setup lacks (EDGE_COMPARE_URL, elkjs, the report file). Before the merge, the routing test passed all 6 checks with a local drawio-mermaid build that has jgraph/drawio-mermaid#20.

🤖 Generated with Claude Code

alderg and others added 9 commits November 18, 2026 10:35
…to draw

The viewer converted the first Mermaid diagram of a page before the
Recursive font of Mermaid 12's redux themes had loaded, so its labels were
measured in a fallback font and the boxes came out about 20 % too narrow
(a class box 331 px wide instead of 397). The final conversion now loads the
fonts mxMermaidToDrawio.getFonts names first, at most 3 s per font, as
draw.io's editor does; a streaming preview made before they were there is
not reused as the result.

A diagram whose statements the parser didn't recognize converted to an empty
frame; it is now an error with draw.io's own message. The headers draw.io
converts that the reference doesn't teach (swimlane-beta, usecase-beta,
agentflow-beta, cynefin-beta, the railroad variants, eventmodeling-beta,
flowchart-elk) are recognized as Mermaid when passed as xml.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scripts/mermaid-to-drawio.js converts Mermaid to an editable .drawio file
when draw.io Desktop isn't installed: it runs draw.io's own converter from
viewer.diagrams.net (HeadlessEditorUi.parseMermaidDiagram, as the desktop
CLI does) in an installed headless Chrome, Edge, Chromium or Brave, with
Node's built-ins only. Only the scripts and fonts are downloaded; the
Mermaid is converted locally and sent nowhere. Without a browser it exits
with 3 and --link prints a #create= link that draw.io converts on open.

The skill uses it when the CLI is missing, instead of rewriting the diagram
as XML; the body stays under 24,000 bytes (23,781). Mirrored byte-identically
to the Codex, Copilot, Cursor and Antigravity plugins; version 1.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One diagram of each type draw.io converts (the reference's 28 plus swimlane,
use case, agent flow, railroad and Cynefin), converted in the app's HTML by
the viewer and by the plugins' mermaid-to-drawio.js, plus every example of
the reference. Checks: cells, not an image; nothing locked; the labels are
cells' text; shapes inside their containers; how many edges may have a loose
end and how many cells may be images, which records what drawio-mermaid
doesn't do yet per type. The class diagram converts first, so the viewer's
font wait is checked against the plugins' converter. Skips without a browser
or the network.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The root README says what every route does with Mermaid and what the
conversion doesn't do yet, the registry description leads with it, and the
app server's AGENTS.md has the font wait, the empty-diagram error, the
per-type test and the gaps per type. The privacy table names the
downloads of the plugins' converter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… read

Node can fire the browser's exit before the last of its stderr is read,
so the "No usable sandbox" line could arrive too late and the script
exited with 3 instead of retrying with --no-sandbox. The exit's error now
waits for stderr to end, at most 1 s, and close() no longer waits for an
exit that has already happened.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… its own text

The preview parses the text up to its last newline but cached the parse
under the whole partial, so a final text that came with its last line
reused the parse without it, and a preview without cells skipped the
"Nothing to draw" error. It is kept now only when the rest after the last
newline is blank and it has cells; mermaid-types.test.js streams both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
drawio-mermaid with jgraph/drawio-mermaid#20 routes the edges of a
swimlane-beta diagram around its shapes with the host's libavoid
(globalThis.Avoid and AvoidRouting). scripts/mermaid-to-drawio.js now
loads libavoid as draw.io does, js/libavoid-js/libavoid.min.js and then
libavoid-routing.js from viewer.diagrams.net, after its bundles. Both are
optional: a file that fails or takes longer than 20 s is skipped, and
the diagram converts as before. The app server's viewer already loads
the two files before drawio-mermaid.

test/mermaid-swimlane-routing.test.js converts Mermaid's swimlane
example through a local mirror of the CDN: the script asks for the
viewer's LIBAVOID_FILES in order, and converts the same shapes with
libavoid answered 404. With a drawio-mermaid that routes (MERMAID_PATH,
or the CDN's once a draw.io release ships it), no edge of the script's
or the viewer's result runs through a shape; unrouted, Pay to Raise
invoice runs through Pick items.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r none

The optional libavoid files shared the 90 s evaluate of the required
bundles, so a slow link could fail the whole load (exit 3) where the
converter alone loaded. And a file given up on after 20 s still ran
whenever it arrived, possibly between two diagrams of one run.

Now the converter loads first, then libavoid in an evaluate of its own
whose errors are ignored: both files are fetched together and run inline,
in their order, only when both have arrived within 20 s. The test sends
libavoid late through its mirror: the diagram converts as without it,
and libavoid that arrived late is not in the page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#120 is in main as one squash commit (3f15a69). This keeps only this
branch's own change on top of it: libavoid loaded after the converter,
the swimlane routing test, 1.3.1. In DEVELOPING.md main's Sandbox
bullet stays, with this branch's libavoid, Swimlanes and Tests text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude 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.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

Only swimlane-beta diagrams use the router, so a run of flowcharts,
sequence or class diagrams no longer downloads libavoid or waits up to
20 s for it. The type comes from draw.io's getMermaidDiagramType in the
page; the all-or-none load and its timeout stay for swimlane runs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@claude claude 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.

My earlier point is fixed: libavoid now loads only when a run includes a swimlane-beta diagram. This run found no new bugs. A human should still look, because the plugins now download and run two more scripts from the CDN.

What was reviewed:

  • The new hasDiagramType check runs before loadOptional. If the converter has no getMermaidDiagramType, it treats every text as a possible swimlane diagram, so libavoid is loaded. Any error in either step is caught, and the diagram converts without libavoid.
  • loadOptional runs both files only if both arrive in time. If either one fails or the timeout fires, it aborts and runs neither.
  • All 5 copies of mermaid-to-drawio.js are byte-identical, and every manifest plus marketplace.json is at 1.3.1.
  • The AGENTS.md and DEVELOPING.md text matches the code. I read the 635-line test but did not run it.
Extended reasoning...

The change adds optional libavoid loading to the 5 identical plugin copies of mermaid-to-drawio.js, a 635-line browser test, doc updates and a version bump to 1.3.1. The new attack surface is that the headless page now fetches two more scripts from viewer.diagrams.net and runs them inline. That host already serves the converter bundles the script trusts. The latest commit fixes the one issue raised earlier (libavoid was loaded for every run), and no CODEOWNERS file covers these paths. I'm deferring instead of approving because the change is a moderately sized feature that runs more remote code and adds a large new test.

@alderg
alderg merged commit 0d8df65 into main Nov 18, 2026
2 checks passed
@alderg
alderg deleted the voice/mermaid-libavoid branch November 18, 2026 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant