Repository navigation
build(deps): update mermaid to v12 - #529
Merged
Merged
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
Compatibility below Mermaid’s supported browser baseline remains unverified in real WebKit 16.x and the app’s diagram preview.
No open issues 🎉
What changed in this PR
Upgrades Mermaid to 12.2.0 while preserving existing diagram styling and targeting Safari 16 compatibility.
Changes:
- Updates Mermaid and its locked dependencies.
- Adds runtime compatibility shims and focused tests.
- Explicitly retains the Dagre layout and classic look.
| File | Description |
|---|---|
src/lib/services/diagram.ts |
Installs shims before loading Mermaid and preserves rendering defaults. |
src/lib/polyfills/mermaid-runtime.ts |
Adds three runtime compatibility shims. |
src/lib/polyfills/mermaid-runtime.test.ts |
Tests shim behavior, native preservation, and stylesheet cleanup. |
package.json |
Updates Mermaid to ^12.2.0. |
bun.lock |
Locks Mermaid 12.2.0 and updated dependencies. |
Review effort: Balanced
mermaid 12 is built for Safari 17.4 (ES2024). kogu keeps macOS 13 as its minimum and the safari16 build target, so the update adds runtime shims instead of raising either. Vite already lowers mermaid's syntax for safari16; the shims cover the APIs it calls without a feature check: - new CSSStyleSheet() (Safari 16.4), used on every render since mermaid 11.15. The shim returns the sheet of an inert <style media="not all"> element, which supports the insertRule/cssRules calls mermaid makes. - URL.canParse (Safari 17), used by @braintree/sanitize-url for links. - Object.groupBy (Safari 17.4), used by chevrotain 13 to validate the use-case diagram grammar. New in mermaid 12. installMermaidPolyfills() runs right before mermaid is imported and installs each shim only when the API is missing. mermaid 12 also switches the default layout to ELK and the default look to "neo". Set layout: 'dagre' and look: 'classic', as the 12.0.0 release notes advise, so existing diagrams render as before and the ELK chunk is only loaded when a diagram asks for it.
seijikohara
force-pushed
the
chore/mermaid-12
branch
from
October 20, 2026 07:46
9fa382e to
1c1165c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
mermaidfrom 11.15 to 12.2.0.safari16as the macOS/Linux build target. mermaid 12 states Safari 17.4+ as its baseline, so this PR adds small runtime shims (src/lib/polyfills/mermaid-runtime.ts), loaded right before mermaid.layout: 'dagre'andlook: 'classic'so existing diagrams render as they do today.What mermaid 12 needs beyond Safari 16
The 12.0.0 release (changeset #8213) raised mermaid's build target to ES2024 / Safari 17.4 and says: "If you need to support older browsers, you may need to polyfill or transpile mermaid". The commit changes only build settings, not application code. I checked the published 12.2.0 package and its dependencies:
safari16; the builtdist/contains nonenew CSSStyleSheet(), unguarded, on every rendercreateCssStyles(), C4 styles<style media="not all">elementURL.canParse, unguarded@braintree/sanitize-url(diagram links)Object.groupBy, unguardedError.captureStackTrace,replaceSync,OffscreenCanvas,trustedTypesRegex: no
vflag,dflag, modifiers or duplicate named groups. The only lookbehind is marked's guarded feature probe. Nothing needs an engine feature that cannot be polyfilled.CSSStyleSheetandURL.canParsewere already needed by the mermaid 11.15+ that kogu ships today. On WebKit before 16.4, every mermaid render currently fails with "Illegal constructor". So the shims also fix an existing problem on older macOS 13 installs. OnlyObject.groupByis new in 12.Each shim installs only when the API is missing. I chose hand-written shims (about 0.5 kB) over core-js because core-js has no
CSSStyleSheetconstructor polyfill, and its two relevant modules would add about 19 kB minified for two one-line functions. The shims follow the spec semantics that matter here:Object.groupByreturns a null-prototype object keyed by property key.Configuration
mermaid 12 makes ELK the default layout and
neothe default look. Following the 12.0.0 release notes ("addlayout: dagre,theme: defaultandlook: classicto your config to keep the old look"),loadMermaid()now setslayout: 'dagre'andlook: 'classic'. A diagram can still opt into ELK through front matter; the ELK chunk then loads on demand. kogu calls onlyinitializeandrender. None of the removed APIs (defaultRenderer, layout-renderer exports, old diagram IDs) are used.Sources
CSSStyleSheet()constructor (16.4),URL.canParse(17),Object.groupBy(17.4), class static blocks (16.4)Test Plan
bun install --frozen-lockfile,bun run lint,bun run format:check,bun run check,bun run buildbun run test: 243 passed after rebasing on the jschardet 4 update, including 4 new tests for the shims: grouping and null prototype,URL.canParse, native implementations kept, and aCSSStyleSheetconstructor that throws "Illegal constructor"safari16production build has no class static blocks in its JS chunks (grep "static {"matches only a string inside the TypeScript language worker)new CSSStyleSheet()throw, as WebKit before 16.4 does. I built a scratch page with kogu'ssafari16target, kogu'sinitializeoptions, and this PR's shim module, and rendered 41 sources covering every diagram family:Error.captureStackTrace.Not verified: a real WebKit 16.x. The only available WebKit is current, and the simulation cannot reproduce WebKit-only rendering differences. Also not verified: the diagram preview inside the app. In the markdown editor preview, fenced code blocks, including mermaid, render as a
CODE_BLOCK_1placeholder onmaintoo, so that page cannot show diagrams today. That is a separate bug.