sveltejs / sveltejs/kit

Make `form.fields` array proxies iterable

Open
#15,833 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

forms
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Description

The experimental form() API supports array fields via form.fields.versions[0].majorVersion.as("number"), but the proxy does not implement Symbol.iterator, so it cannot be used in {#each} blocks.

Current workaround
<!-- Requires a separate data source just to drive iteration -->
{#each items as _, index (index)}
  <input {...form.fields.versions[index]?.majorVersion.as("number")} />
{/each}

This forces duplicated iteration sources, awkward ?. chaining (TS index signature returns T | undefined), and prevents passing array field proxies to components expecting iterables.

Proposed
{#each form.fields.versions as version}
  <input {...version.majorVersion.as("number")} />
{/each}

Implement Symbol.iterator (and length) on create_field_proxy for paths resolving to arrays, yielding the same proxies that indexed access already produces.

Related
  • #14662 — array mutation helpers (different scope)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at create_field_proxy, which is the entry point named in the issue, and trace how indexed access produces array field proxies. Add coverage for iteration and length on array paths, confirming that iteration yields the same proxies as indexed access. Done means form.fields.versions works directly in an {#each} block without a separate data source.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.