Skip to content

Commit c34ea5e

Browse files
calebporzioNightFurySL2001claude
committed
Warn when x-for template has multiple root elements
x-for silently discards all but the first child element of a template. This adds a console.warn so users know what's happening instead of debugging invisible behavior. Co-Authored-By: NFSL2001 <NightFurySL2001@users.noreply.github.com> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b357068 commit c34ea5e

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

  • packages/alpinejs/src/directives

packages/alpinejs/src/directives/x-for.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ function loop(templateEl, iteratorNames, evaluateItems, evaluateKey) {
111111
return
112112
}
113113

114+
if (templateEl.content.children.length > 1)
115+
warn('x-for templates require a single root element, additional elements will be ignored.', templateEl)
116+
114117
let clone = document.importNode(templateEl.content, true).firstElementChild
115118
let reactiveScope = reactive(scope)
116119
addScopeToNode(clone, reactiveScope, templateEl)

0 commit comments

Comments
 (0)