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: Remove element markers to allow reinitialization. #4509

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 0 additions & 11 deletions packages/alpinejs/src/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,28 +82,18 @@ let initInterceptors = []

export function interceptInit(callback) { initInterceptors.push(callback) }

let markerDispenser = 1

export function initTree(el, walker = walk, intercept = () => {}) {
// Don't init a tree within a parent that is being ignored...
if (findClosest(el, i => i._x_ignore)) return

deferHandlingDirectives(() => {
walker(el, (el, skip) => {
// If the element has a marker, it's already been initialized...
if (el._x_marker) return

intercept(el, skip)

initInterceptors.forEach(i => i(el, skip))

directives(el, el.attributes).forEach(handle => handle())

// Add a marker to the element so we can tell if it's been initialized...
// This is important so that we can prevent double-initialization of
// elements that are moved around on the page.
if (!el._x_ignore) el._x_marker = markerDispenser++

el._x_ignore && skip()
})
})
Expand All @@ -113,7 +103,6 @@ export function destroyTree(root, walker = walk) {
walker(root, el => {
cleanupElement(el)
cleanupAttributes(el)
delete el._x_marker
})
}

Expand Down
Loading