Summary
Attempting to programmatically fill a slot node inside an instance throws:
in appendChild: Cannot move node. New parent is an instance or is inside of an instance
Reproduction
const buttonVariant = ...; // ComponentNode containing a SlotNode named 'icon'
const instance = buttonVariant.createInstance();
instance.setProperties({ [showIconKey]: true }); // make slot visible
const slotNode = instance.findOne(n => n.name === 'icon'); // finds the SlotNode
const iconInstance = iconComponent.createInstance();
slotNode.appendChild(iconInstance); // throws
Expected behavior
Slots are explicitly designed to accept dropped content — that's their entire purpose. The plugin API should allow placing a component instance into a slot node, mirroring what a designer can do by dragging in the Figma UI.
Either appendChild should work on SlotNodes inside instances, or a dedicated method (e.g. slotNode.assignContent(componentNode)) should be provided.
Context
Building a plugin that generates component documentation pages. For the examples frame, we want to show buttons with icons already placed in their slots. We had to fall back to detachInstance() to work around this, which means the examples are no longer live instances.
Noticed this while working against the owong/slots-plugin-typings branch — tagging in case that's the right person to loop in.
Workaround
const frame = instance.detachInstance(); // slot becomes a plain FrameNode
const iconFrame = frame.findOne(n => n.name === 'icon');
iconFrame.appendChild(iconInstance); // works, but instance is now detached
Summary
Attempting to programmatically fill a slot node inside an instance throws:
Reproduction
Expected behavior
Slots are explicitly designed to accept dropped content — that's their entire purpose. The plugin API should allow placing a component instance into a slot node, mirroring what a designer can do by dragging in the Figma UI.
Either
appendChildshould work onSlotNodes inside instances, or a dedicated method (e.g.slotNode.assignContent(componentNode)) should be provided.Context
Building a plugin that generates component documentation pages. For the examples frame, we want to show buttons with icons already placed in their slots. We had to fall back to
detachInstance()to work around this, which means the examples are no longer live instances.Noticed this while working against the
owong/slots-plugin-typingsbranch — tagging in case that's the right person to loop in.Workaround