Skip to content

Signal Forms: how should opaque array values be modeled - field tree creates per-element child nodes for Field<T[]> #68511

@sonukapoor

Description

@sonukapoor

Opening this to track a design question that came up during the select[multiple] prototype (#67563, #68350) - flagged by @leonsenft for broader team discussion.

The problem

isObject in type_guards.ts returns true for arrays (typeof [] === 'object'). This means a Field<string[]> passes the object check in structure.ts, Object.keys is called on the array value, and one child node per element is created ('0', '1', etc.). As the array length changes, those nodes churn.

For something like a multi-select, the selected values are atomic - there's no meaningful field('0'). The current field tree has no way to express that distinction.

Possible directions

  • A Leaf<T> wrapper that marks a value as opaque, suppressing child materialization regardless of type
  • Set<string> as the value type - Object.keys(new Set(...)) is [], so no child nodes with the current architecture
  • A schema-level opt-out on the field's logic that suppresses child materialization for specific fields

Wondering whether others have thoughts on the right shape for this, especially given the broader Signal Forms API direction for v22+.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: formsgemini-triagedLabel noting that an issue has been triaged by gemini

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions