Skip to content
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
1 change: 1 addition & 0 deletions packages/alpinejs/src/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function onMutate(mutations) {
for (let node of addedNodes) {
// If the node was eventually removed as part of one of his
// parent mutations, skip it
if (removedNodes.has(node)) continue
if (! node.isConnected) continue

delete node._x_ignoreSelf
Expand Down
24 changes: 24 additions & 0 deletions tests/cypress/integration/mutation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,27 @@ test('no side effects when directives are added to an element that is removed af
get('span').should(haveText('0'))
}
)
test(
"previously initialized elements are not reinitialized on being moved",
html`
<script>
let count = 0;
document.addEventListener('alpine:init', () => {
Alpine.directive('test', el => {
if (count++ > 3) return;
el.textContent = count;
let wrapper = document.createElement('div');
wrapper.setAttribute('class', 'bg-blue-300 p-8');
el.parentNode.replaceChild(wrapper, el);
wrapper.appendChild(el);
});
});
</script>
<div x-data>
<div class="bg-red-300 w-32 h-32" x-test></div>
</div>
`,
({ get }) => {
get("[x-test]").should(haveText("1"));
}
);