#8172·mermaid

ELK: `elk.cycleBreakingStrategy` is silently stripped from frontmatter/init config — missing from `defaultConfig.elk`

Author: mrinaldhillonCreated Aug 30, 2026Updated Sep 28, 2026
LabelsStatus: Triage

Description

@mermaid-js/layout-elk reads seven options from config.elk: mergeEdges, nodePlacementStrategy, nodePlacementAlignment, forceNodeModelOrder, considerModelOrder, keepEntryNodeOnTop, and cycleBreakingStrategy (forwarded as elk.layered.cycleBreaking.strategy, with no fallback of its own).

defaultConfig.elk in mermaid core lists the first six but omits cycleBreakingStrategy. Because sanitizeDirective keeps only keys present in keyify(defaultConfig), any elk.cycleBreakingStrategy a diagram sets via YAML frontmatter or a %%{init}%% directive is silently deleted before the layout plugin ever sees it. The same key delivered via mermaid.initialize() site config (e.g. mmdc --configFile) works — which is what makes the in-source form's silence surprising: the option is live, only the in-diagram delivery path eats it.

cycleBreakingStrategy is the one ELK option that steers layer order on cyclic graphs (e.g. MODEL_ORDER makes ELK break cycles at edges running against declaration order, matching how dagre reads the same source), so per-diagram authoring is exactly where it's wanted — a site-wide initialize() value can't express "this one diagram needs MODEL_ORDER."

Verified at the [email protected] tag: packages/mermaid/src/defaultConfig.ts still omits the key from the elk block.

Steps to reproduce

cycle.mmd:

---
config:
  layout: elk
  elk:
    cycleBreakingStrategy: MODEL_ORDER
---
flowchart LR
    K["core"] -- a --> M["model"]
    K -- b --> M
    M -- c --> K
    M --> P["presentation"]
bash
# frontmatter form: key stripped — node positions identical to a no-key render
mmdc -i cycle.mmd -o fm.svg

# same key via site config: layout changes (M is no longer forced to layer 0)
echo '{"elk":{"cycleBreakingStrategy":"MODEL_ORDER"}}' > cfg.json
mmdc -i cycle.mmd -o cfg.svg --configFile cfg.json

Compare node translate(x,y) positions in the two SVGs: fm.svg matches a render with no key at all; cfg.svg differs.

Expected behavior

The frontmatter/init form either works or is rejected loudly — not silently dropped.

Suggested fix

One line in defaultConfig's elk block (mirroring elkjs's documented default for org.eclipse.elk.layered.cycleBreaking.strategy):

typescript
cycleBreakingStrategy: 'GREEDY',

plus the matching entry in the config schema/docs, as exists for the other six keys.

Environment

  • mermaid 11.16.0 (via mermaid-cli) and the [email protected] tag (source inspection) — behavior identical
  • @mermaid-js/layout-elk 0.2.2 and 0.2.3
  • Also reproduced in a WKWebView embedding mermaid 11.17.2 + layout-elk