Skip to content

splitComponentByConcern defaults props to [] instead of {} #84

@jordan-n-schmidt

Description

@jordan-n-schmidt

Summary

In packages/cli/src/Writers/DataTransformers.ts, the splitComponentByConcern function defaults props to an empty array when the source component has no props:

const api: ComponentApiData = {
  title: data.title,
  anatomy: data.anatomy,
  props: data.props || [],  // should be {}
  metadata: data.metadata
};

The TypeScript interface also types it incorrectly:

export interface ComponentApiData {
  props: any[];  // should be Record<string, any> or object
}

Root cause

The Anova Figma plugin correctly returns undefined for components with no props (via Props.data() returning undefined when _items is empty). When the CLI runs in --split-concerns mode, splitComponentByConcern fills in the missing key with [] instead of {}.

Impact

The schema (packages/schema/schema/component.schema.json) defines Props as:

"Props": {
  "type": "object",
  "additionalProperties": { "$ref": "#/definitions/AnyProp" }
}

Downstream consumers calling Object.keys(configurations) or similar object operations on the renamed props field get unexpected behavior when it's an array.

Observed in production for egdsDivider and egdsSearchBarExperimental — both are components with no Figma properties.

Suggested fix

export interface ComponentApiData {
  props: Record<string, any>;
}

// In splitComponentByConcern:
props: data.props || {},

// Same for extractApiFromSubcomponents:
props: data.props || {},

Same issue in SubcomponentApiData

export interface SubcomponentApiData {
  props: any[];  // also typed as array
}

And in extractApiFromSubcomponents:

props: data.props || [],  // also defaults to []

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions