Skip to content

Render: instance-swap prop configurations fall back to the component default #300

Description

@nathanacurtis

Problem

When a spec configures an instance-swap property — an icon on an avatar, for example — render does not apply it. The instance keeps whatever its component defaults to, so a component specified with one icon renders with another.

Background

Instance-swap values in a spec are component names. Figma's setProperties expects a published component key. Passing the name is rejected, so the configuration is currently skipped and reported:

⚠ [writer] propConfig "Avatar.icon": instance-swap properties take a component key, not a name — skipping

Skipping is deliberate — it was previously throwing and taking every other property on that instance down with it (fixed in #291) — but it leaves the configured value unapplied.

Solution

Resolve the configured name to a component key before applying it, using the manifests render already carries for this purpose:

  • instanceIdManifest — spec key to component reference
  • glyphIdManifest — glyph content name to component reference, which is how icons resolve elsewhere in the writer
  • InstanceElement.resolveEntry — same-file node id first, published-key import when the component lives in another file

Report and skip only when the name resolves to nothing.

Acceptance criteria

  • A spec configuring an instance-swap prop renders with the configured component, not the default
  • Icons resolve through the glyph manifest, including icons that live in a separate library file
  • An unresolvable name is reported clearly and skips that property alone
  • Round-trip diffs show instance-swap propConfigurations surviving

Fixtures

AvatarGroupAvatar.icon is the live example

Subtask of #204.

Metadata

Metadata

Assignees

No one assigned

    Labels

    generatorspecs-from-figma processing engine

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions