Skip to content

Commit

Permalink
Fix issue with mutations running in the wrong order when triggered by…
Browse files Browse the repository at this point in the history
… third party libs
  • Loading branch information
SimoTod committed Nov 15, 2021
1 parent aa7167b commit c3e2f58
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/alpinejs/src/lifecycle.js
Expand Up @@ -14,7 +14,7 @@ export function start() {
startObservingMutations()

onElAdded(el => initTree(el, walk))
onElRemoved(el => nextTick(() => destroyTree(el)))
onElRemoved(el => destroyTree(el))

onAttributesAdded((el, attrs) => {
directives(el, attrs).forEach(handle => handle())
Expand Down
16 changes: 8 additions & 8 deletions packages/alpinejs/src/mutation.js
Expand Up @@ -160,14 +160,6 @@ function onMutate(mutations) {
onAttributeAddeds.forEach(i => i(el, attrs))
})

for (let node of addedNodes) {
// If an element gets moved on a page, it's registered
// as both an "add" and "remove", so we want to skip those.
if (removedNodes.includes(node)) continue

onElAddeds.forEach(i => i(node))
}

for (let node of removedNodes) {
// If an element gets moved on a page, it's registered
// as both an "add" and "remove", so we want to skip those.
Expand All @@ -176,6 +168,14 @@ function onMutate(mutations) {
onElRemoveds.forEach(i => i(node))
}

for (let node of addedNodes) {
// If an element gets moved on a page, it's registered
// as both an "add" and "remove", so we want to skip those.
if (removedNodes.includes(node)) continue

onElAddeds.forEach(i => i(node))
}

addedNodes = null
removedNodes = null
addedAttributes = null
Expand Down

0 comments on commit c3e2f58

Please sign in to comment.