Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix x-if and x-for double init on clone phase #4015

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/alpinejs/src/directives/x-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { initTree } from '../lifecycle'
import { mutateDom } from '../mutation'
import { warn } from '../utils/warn'
import { dequeueJob } from '../scheduler'
import { skipDuringClone } from '../clone'

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

initTree(clone)
// These nodes will be "inited" as morph walks the tree...
skipDuringClone(() => initTree(clone))()
})

if (typeof key === 'object') {
Expand Down
6 changes: 4 additions & 2 deletions packages/alpinejs/src/directives/x-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { mutateDom } from '../mutation'
import { walk } from "../utils/walk"
import { dequeueJob } from '../scheduler'
import { warn } from "../utils/warn"
import { skipDuringClone } from '../clone'

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

initTree(clone)
// These nodes will be "inited" as morph walks the tree...
skipDuringClone(() => initTree(clone))()
})

el._x_currentIfEl = clone
Expand All @@ -33,7 +35,7 @@ directive('if', (el, { expression }, { effect, cleanup }) => {
node._x_effects.forEach(dequeueJob)
}
})

clone.remove();

delete el._x_currentIfEl
Expand Down
Loading