d2lang/d2 · error

Connection "%s" is a self loop on a container, but layout en

Error message

Connection "%s" is a self loop on a container, but layout engine "%s" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.

What it means

FeatureSupportCheck rejects self-loop edges whose source and destination are the same container when the engine lacks DESCENDANT_EDGES support. Containers cannot loop to themselves in engines without this feature.

Source

Thrown at d2plugin/plugin_features.go:70

			_, isKey := g.Root.HasChild(d2graph.Key(obj.NearKey))
			if isKey {
				if _, ok := featureMap[NEAR_OBJECT]; !ok {
					return fmt.Errorf(`Object "%s" has "near" set to another object, but layout engine "%s" only supports constant values for "near". See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, obj.AbsID(), info.Name)
				}
			}
		}
	}
	if _, ok := featureMap[DESCENDANT_EDGES]; !ok {
		for _, e := range g.Edges {
			// descendant edges are ok in sequence diagrams
			if e.Src.OuterSequenceDiagram() != nil || e.Dst.OuterSequenceDiagram() != nil {
				continue
			}
			if !e.Src.IsContainer() && !e.Dst.IsContainer() {
				continue
			}
			if e.Src == e.Dst {
				return fmt.Errorf(`Connection "%s" is a self loop on a container, but layout engine "%s" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)
			}
			if e.Src.IsDescendantOf(e.Dst) || e.Dst.IsDescendantOf(e.Src) {
				return fmt.Errorf(`Connection "%s" goes from a container to a descendant, but layout engine "%s" does not support this. See https://d2lang.com/tour/layouts/#layout-specific-functionality for more.`, e.AbsID(), info.Name)
			}
		}
	}
	return nil
}

View on GitHub (pinned to 0d69dca6f5)

Solutions

  1. Switch to a layout engine supporting container self-loops (e.g. ELK)
  2. Remove the self-loop edge on the container
  3. Point the loop at a child object instead of the container

Example fix

// before
c1.c1: { style.stroke: red }
// after
c1.a.c1.a // loop on a child, or use layout: elk
Defensive patterns

Strategy: validation

Validate before calling

for _, e := range g.Edges {
	if e.Src == e.Dst && e.Src.IsContainer() && engineName != "elk" {
		// container self-loop unsupported; restructure
	}
}

Try / catch

if err := engine.FeatureSupportCheck(ctx, g); err != nil {
	return fmt.Errorf("container self-loop unsupported: %w", err)
}

Prevention

When it happens

Trigger: An edge where e.Src == e.Dst and both are containers, and the layout engine's feature map lacks DESCENDANT_EDGES.

Common situations: Drawing a loop edge on a group/box containing children with dagre; diagrams authored against ELK reused with another engine.

Related errors


AI-assisted analysis of d2lang/d2@0d69dca6f5 (2026-08-31). Data as JSON: /api/errors/95d0f3f8fa6c0b11. Report an issue: GitHub.