collapsePrimitiveWrapper
When enabled, a component whose root is a container holding exactly one child is collapsed: the wrapper is stripped and the child becomes the spec root. When disabled, the container is emitted as root regardless of structure.
| File | config/settings.yaml |
| Path | spec.collapsePrimitiveWrapper |
| Type | boolean |
| Default | true |
The eligibility rules below are what make this safe as a default. Two conditions carry it: the wrapper must carry no style the child cannot hold, and the child must be the wrapper’s box. Collapse is a claim that the two layers were one box all along, so a child that only occupies part of its wrapper is kept as its own element, where its position and its own size still mean something. Turn the setting off when you want the Figma layer structure preserved exactly — most often to keep a role annotated on a collapsing component’s child, as the last section explains.
Example
spec: collapsePrimitiveWrapper: falseResult
Without collapse (false) a Heading component emits a two-node anatomy with a container root:
anatomy: root: type: container label: type: text parent: rootWith collapse (true) the wrapper is stripped and the leaf becomes root, carrying the wrapper’s box and the leaf’s own styling:
anatomy: root: type: text $extensions: com.figma.name: Labelelements: root: styles: width: 200 height: 40 textColor: "#000000FF" content: LabelThe $extensions.com.figma.name field on the anatomy root carries the Figma layer name so the source layer remains traceable.
Qualifying shapes
Two shapes qualify, and they are tested differently because they lose different things:
- A
textorglyphleaf. A container merges into a leaf, where container styles have nowhere to go, so the wrapper must carry none that matter. This eliminates structural noise for typographic and icon primitives — Heading, Paragraph, Body, Label, Icon — where the container adds no design-system meaning. - A slot. Both nodes are containers with the same style signature, so the merge discards nothing and no style is tested. This applies to layout primitives — a frame whose only content is the slot its children fill.
Eligibility
A component qualifies for collapse when all of the following are true:
- The root element type is
container. - The root has exactly one anatomy-visible child. And either of the following.
For a leaf child:
- That child’s type is
textorglyph. - The child has no children of its own.
- The root carries no slot binding on its children.
- The root carries none of the following styles after default/zero values are stripped:
clipsContent,cornerRadius,strokes,strokeAlign,strokeWeight,itemSpacing,padding,effects,backgroundColor,cornerSmoothing. - The child fills the root exactly — flush at its origin, and the same width and height.
For a slot child:
- That child is a container whose
childrenis bound to a slot property, and that property is the component’s only slot. - No variant overrides the binding.
- The slot fills the root exactly — the same requirement as a leaf, with no exemption for a padded root.
- No style test applies — both nodes are containers, so nothing is discarded. Where both carry a style key, the slot’s value is kept, except for a size the root binds to a token.
The one-box requirement is the only geometric test, and it is why a padded root wrapping a filling slot stays two elements. Two containers discard nothing between them where style keys are concerned, which is what ADR-083 rests on; geometry is the exception, because the root’s measured size and the slot’s FILL are both true of their own layer and contradict each other on one.
Collapse is all-or-nothing: if any variant in the component set fails the eligibility check, no collapse occurs for any variant. The one-box test is checked per variant too — a size variant whose child stops filling its wrapper disqualifies the whole component.
What the collapsed element carries
Two Figma layers become one element, so every style key has to resolve to one layer’s value.
| Key group | Resolves to |
|---|---|
rotation, visible, opacity, locked | the child’s, or the root’s where the child has none |
layoutSizingHorizontal, layoutSizingVertical | the child’s, or the root’s where the child has none |
width, height, minWidth, minHeight, maxWidth, maxHeight | whichever layer binds a variable; the root’s when both do, the child’s when neither does |
position, top, bottom, start, end, centerHorizontalOffset, centerVerticalOffset | dropped |
| everything else | the child’s — it is the layer that survives |
A bound size beats a measured one. A token names what the design system declares; a raw number is only what Figma measured. So a root bound to DS Sizing/icon/small wrapping a child Figma measured at 16 collapses to the token, not the 16. Where both layers bind a token, the root’s wins — it is the component’s outer boundary, and its token is what a consumer means by the component’s size.
Placement is dropped, not conveyed. Offsets describe where an element sits inside its parent, and the collapsed element is the root — a root has no parent bounds to be positioned within, so capture records no position and no offsets on one. Because collapse requires the two boxes to be the same, the child’s offsets are flush by construction and describe a wrapper that no longer exists.
This matters most for a child of a root with no auto-layout. Capture writes position: ABSOLUTE for any element placed by coordinates rather than by a parent’s stack — the parent not stacking is what triggers it, whatever the child’s own Figma layoutPositioning says. So a glyph sitting flush in a plain 16×16 frame is recorded as absolutely positioned with four 0% edges, and carrying those onto the root would tell render to stretch the recreated glyph to its parent’s box instead of sizing it from its own token.
Collapsing a slot
Without collapse (false) a Layout component emits two boxes:
anatomy: root: type: container children: type: slot parent: rootWith collapse (true) the wrapper is stripped and the slot binding moves onto the root:
anatomy: root: type: container $extensions: com.figma.name: Childrenelements: root: children: $binding: "#/props/children"As with a leaf, $extensions.com.figma.name carries the surviving layer’s Figma name so the source layer remains traceable.
Grid slots
A slot laying its content out as a grid arrives here already collapsed once: the slotGrid convention folds the grid frame onto the slot, which leaves a root wrapping one slot — the shape this rule removes. So a grid slot with nothing else in the chain lands as a single container carrying the grid.
elements: root: children: $binding: '#/props/slot' examples: - $slotContent: '#/components/cardGrid/slotContentExamples/cardGrid__slot__default' styles: layoutMode: GRID gridColumns: 5To learn more, read about the slot grid convention.
Roles on a collapsed root
A collapse turns two Figma layers into one anatomy element, and either layer may carry a role: annotation. The element records which one did, because render has to put each annotation back on the layer it came from:
role— the component node was annotated.$extensions.com.figma.childRole— the collapsed child was annotated.
Four cases, and the pair distinguishes all four:
role | childRole | Annotated in Figma | Render writes back to |
|---|---|---|---|
| present | absent | the component node | the component node |
| absent | present | the collapsed child | the recreated child |
| present | present | both layers | both layers |
| absent | absent | neither | neither |
childRole is recorded whenever the child was annotated, even when both layers name the same concept. Omitting it in that case would make “both were annotated” indistinguishable from “only the root was”, and render would drop the child’s annotation.
The child’s role is deliberately not merged into role, for the same reason: merging makes the child-only case look like the two-role case. The cost is that a role annotated on a collapsing component’s child emits no code — only role reaches React and Web Components. To make a role affect generated output on a component that collapses, annotate the component node, or set collapsePrimitiveWrapper: false for that library.