mermaid
mermaid copied to clipboard
Stable generation for random identities in svg to aid in cache-busting/build processes
Is your feature request related to a problem? Please describe. When creating SVG diagrams, the id associated with the elements of the diagram change even if the source specification did not change. The presents challenges when using mermaid for part of a build process or static website.
Describe the solution you'd like Ideally it would be nice to specify how the random part of Identities are generated. e.g. some formal API way of changing how identities are generated so they can instead by stable instead of dynamic.
Alternatively it would also work to default to a stable id generation (e.g. not use Math.random, but use some other randomizer that allows setting a specific seed (seedrandom.js for example provides this).
Ideally would like to seed the rng off the mmd spec.
Describe alternatives you've considered
Looked at solving this at the mermaid-cli layer instead, however the intent there is to be a thin wrapper over mermaid, so was not an appropriate place to deal with the issue, especially given any solution there would stop working if mermaid changed the random number generation for some other reason, as it would not be going via a mermaid API.
https://github.com/mermaid-js/mermaid-cli/issues/33
A workarround with PowerShell Core :
Get-ChildItem .\*.mmd | ForEach-Object {
Write-Host "** $($_.Name)"
docker run --rm -it -v $PWD\:/data minlag/mermaid-cli -i "/data/$($_.Name)"
((Get-Content "$_.svg" -Raw) -match '^\<svg.id="(?<id>.*?)"') | Out-Null
$Id = $Matches["id"]
$NewId = $_.Name.ToLower().Replace('.', '-')
((Get-Content "$_.svg" -Raw)) -replace $Id, $NewId | Set-Content "$_.svg"
}
the svg id tag of a generated mermaid diagram svg is always the unix epoch timestamp. Searching for the ID and replacing it works, but it would be cool to have something better. I would suggest an option to just use "mermaid" as id
the svg id tag of a generated mermaid diagram svg is always the unix epoch timestamp. Searching for the ID and replacing it works, but it would be cool to have something better. I would suggest an option to just use "mermaid" as id
This is a good catch! I tried to locate where this happens and have noticed that even though mermaid
has a config to enable deterministicIds
, taking an example of erRenderer
, it generates new ids using uuid5
regardless of the top-level mermaind
configs. Could someone double check if that could be a part of the issue? ✌️
💭 I suppose that this might be persistent across other renderers but have not checked it thoroughly yet (e.g. there's some contrast evident when looking at the classRenderer
and classRenderer-v2
which seems to rely only on the original source IDs and a counter).
We have this issue on the prisma-erd-generator repo. We had thought upgrading to v9 of mermaid caused the issue but after downgrading to v8 we still have this problem. We have deterministicIds
set to true in the mermaid config as well