Skip to content

Commit 2f41cf9

Browse files
knsvclaude
andcommitted
fix(dagre): don't prebuild icon/image labels (lost padding + classDef color)
prebuildNodeLabels builds and measures leaf-node labels up front, but icon/image shape handlers set node.labelStyle (the classDef-derived label color), override node.width, and pass a shape-specific label class ('icon-shape'/'image-shape') to labelHelper *after* the prebuild pass. A prebuilt icon/image label was therefore built and measured with the wrong class, stale style and stale width — dropping the label's padding and its classDef color (e.g. white text rendered black). Exclude node.icon/node.img from the prebuild filter so they fall back to the inline build path inside their handler. Regular shapes keep the batched prebuild: they pass getNodeClasses(node) and don't override width, matching what prebuild uses, so they're unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ecae742 commit 2f41cf9

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

  • packages/mermaid/src/rendering-util/layout-algorithms/dagre

packages/mermaid/src/rendering-util/layout-algorithms/dagre/index.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,24 @@ const measureDagreGraph = async ({
296296
// back-to-back (one reflow) instead of a forced reflow per node. Clusters recurse
297297
// into their own group and linked nodes get their own wrapper, so they're left to
298298
// the inline path in the loop below.
299+
//
300+
// Icon/image shapes are also left to the inline path: their handlers set
301+
// `node.labelStyle` (classDef-derived label colour) and `node.width`, and pass a
302+
// shape-specific label class ('icon-shape'/'image-shape') to `labelHelper` *after*
303+
// this prebuild pass. A label prebuilt here would be built and measured with the
304+
// wrong class, stale style and stale width — losing the label's padding and colour.
299305
const prebuiltLeafNodes = graph
300306
.nodes()
301307
.filter((v) => {
302308
const node = graph.node(v);
303-
return node && !node.clusterNode && graph.children(v).length === 0 && !node.link;
309+
return (
310+
node &&
311+
!node.clusterNode &&
312+
graph.children(v).length === 0 &&
313+
!node.link &&
314+
!node.icon &&
315+
!node.img
316+
);
304317
})
305318
.map((v) => graph.node(v));
306319
await prebuildNodeLabels(nodes, prebuiltLeafNodes);

0 commit comments

Comments
 (0)