Inconsistent SVG Identifiers

I generate a large number of SVG files with GoJS 2.1.54 in Chromium using Playwright 1.18.1 . Occasionally I come across an instance where the same input produces different id values in the SVG output.

For example, one run will produce a diagram with:

<clipPath id="mainClip1615">
<filter id="SHADOW1670" ... >

Whereas another run will produce a diagram with:

<clipPath id="mainClip1614">
<filter id="SHADOW1669" ... >

I only notice the change because the file is version controlled. I don’t have a reproducible example because I haven’t isolated the conditions under which it consistently occurs. Do you have any insight into why this might occur and what, if anything, could be done to address it?

I think it depends on what and how many objects it allocates. Note that a single TextBlock renders as possibly many SVG single-line text objects, and their number might vary due to font variation and measurements.

We’ll look into always starting with the same number, though.

We make the output of every call to makeSVG unique so that there are no ID collisions if you are adding multiple resulting SVGs to a single page. We will consider adding a way to force makeSVG to produce consistent names, but if you need them to be consistent, for now, it may be best to do that on a post-processing step. (eg call svg.getElementsByTagName('filter'), find each of their IDs, and replace them with your own schema.

Something like:

// This would replace the GRAD[number] which we produce with a number of your own choosing
var svg = myDiagram.makeSVG();
var yourOwnUnique = 9000;
var ids = [];
var collection = s.getElementsByTagName('linearGradient');
for (var i = 0; i < collection.length; i++) {
for (var i = 0; i < ids.length; i++) {
  svg.innerHTML.replaceAll(ids[i], yourOwnUnique++);