Skip to content

Add wui.Keyed for stable row identity in the browser - #23

Merged
archlemon merged 1 commit into
mainfrom
feat/keyed
Nov 28, 2026
Merged

archlemon merged 1 commit into
mainfrom
feat/keyed

Conversation

@archlemon

Copy link
Copy Markdown
Member

Summary

Implements #21.

  • wui.Keyed(key, el) gives el an identity the patching renderer (Patch the DOM instead of replacing it on every render #19) matches on. Inserting at the front of a keyed list moves the existing row nodes and creates one, instead of re-patching every row from the insertion point down. Per-row browser state stays with its row.
  • List items carry their Keyed child's key onto the <li>, since that wrapper is the node being matched.
  • Transparent elsewhere: no extra markup; styleOf reads through it, so a Box still sees the child's Grow/MinWidth; a keyed Flex() still stretches (new unkeyed helper for the TUI's spacer checks); the TUI renders the child unchanged.
  • The TUI focus-ring and form-value walkers now fall back to Children() for container types instead of listing each one, so Keyed (and any future wrapper) needs no case there.

Test plan

  • Unit: Keyed produces identical markup apart from the key and passes the Row context through (spacer axis); TUI output with keyed children and a keyed Flex matches the unkeyed tree; a button inside Keyed is in the focus ring
  • e2e TestKeyedRowsMoveInsteadOfRepatching: after prepending a row, the existing rows' DOM nodes are the same objects (marker survives) and the order is right. It failed before list items took their child's key.
  • go test ./..., make e2e, both vets

Closes #21

Keyed(key, el) gives a child an identity the patching renderer matches
on, so inserting at the front of a keyed list moves the existing rows
and inserts one instead of re-patching every row. List items carry
their Keyed child's key onto the <li>.

Keyed is transparent everywhere else: no markup, Box reads Grow and
MinWidth through it, a keyed Flex still stretches, and the TUI renders
the child unchanged. The TUI focus and form-value walkers now recurse
through Children for container types, so wrappers like Keyed need no
case of their own.

Closes #21
@archlemon
archlemon merged commit 39e033e into main Nov 28, 2026
2 checks passed
@archlemon
archlemon deleted the feat/keyed branch November 28, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explicit keys for list rows: wui.Keyed(key, el)

1 participant