Add support for Set objects in x-for loop function#4672
Add support for Set objects in x-for loop function#4672calebporzio merged 3 commits intoalpinejs:mainfrom
Conversation
- Convert Set/Map to Array early instead of treating Set as an object - Sets flow through the array path (semantically correct — Sets are iterables, not key-value stores) - Maps convert to [[key, value], ...] arrays, enabling natural destructuring - Added Cypress tests for both Set and Map iteration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR Review: #4672 — Add support for Set objects in x-for loop functionType: Feature What's happening (plain English)
The contributor's original fix converted the Set into a plain object with numeric keys ( Other approaches considered
Changes Made
Test Results
Code ReviewThe fix is 2 lines in One consideration: SecurityNo security concerns identified. VerdictMerge. The bug is real (silent empty render for Sets), the fix is minimal (2 lines), and it follows Alpine's existing early-normalization pattern. I rewrote the contributor's approach to be semantically correct (Sets as arrays, not fake objects) and added Map support as a natural extension. Tests are clean and regression is verified. Reviewed by Claude |
Description
x-fordoesn't handleSet.We are using
Object.entries(items).Setdoes not store values as enumerable object keys.This PR adds the
x-forto convert into key-value if theitemsis aSetobject, then pass it into the existingObject.entries(items).References