Skip to content

SlotNode: Cannot place content into slot inside instance via appendChild #351

@kevinj-rsp

Description

@kevinj-rsp

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions