Skip to content

Commit 84fd08d

Browse files
authored
fix (#4015)
1 parent bf36275 commit 84fd08d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { initTree } from '../lifecycle'
66
import { mutateDom } from '../mutation'
77
import { warn } from '../utils/warn'
88
import { dequeueJob } from '../scheduler'
9+
import { skipDuringClone } from '../clone'
910

1011
directive('for', (el, { expression }, { effect, cleanup }) => {
1112
let iteratorNames = parseForExpression(expression)
@@ -205,7 +206,8 @@ function loop(el, iteratorNames, evaluateItems, evaluateKey) {
205206
mutateDom(() => {
206207
lastEl.after(clone)
207208

208-
initTree(clone)
209+
// These nodes will be "inited" as morph walks the tree...
210+
skipDuringClone(() => initTree(clone))()
209211
})
210212

211213
if (typeof key === 'object') {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { mutateDom } from '../mutation'
66
import { walk } from "../utils/walk"
77
import { dequeueJob } from '../scheduler'
88
import { warn } from "../utils/warn"
9+
import { skipDuringClone } from '../clone'
910

1011
directive('if', (el, { expression }, { effect, cleanup }) => {
1112
if (el.tagName.toLowerCase() !== 'template') warn('x-if can only be used on a <template> tag', el)
@@ -22,7 +23,8 @@ directive('if', (el, { expression }, { effect, cleanup }) => {
2223
mutateDom(() => {
2324
el.after(clone)
2425

25-
initTree(clone)
26+
// These nodes will be "inited" as morph walks the tree...
27+
skipDuringClone(() => initTree(clone))()
2628
})
2729

2830
el._x_currentIfEl = clone
@@ -33,7 +35,7 @@ directive('if', (el, { expression }, { effect, cleanup }) => {
3335
node._x_effects.forEach(dequeueJob)
3436
}
3537
})
36-
38+
3739
clone.remove();
3840

3941
delete el._x_currentIfEl

0 commit comments

Comments
 (0)