Caleb Porzio 1 an în urmă
părinte
comite
51dfacd709

+ 1 - 13
packages/alpinejs/src/lifecycle.js

@@ -81,23 +81,13 @@ export function interceptInit(callback) { initInterceptors.push(callback) }
 export function initTree(el, walker = walk, intercept = () => {}) {
     deferHandlingDirectives(() => {
         walker(el, (el, skip) => {
-            if (el._x_inited) {
-                if (el._x_ignore) skip()
-
-                return
-            }
-
             intercept(el, skip)
 
             initInterceptors.forEach(i => i(el, skip))
 
             directives(el, el.attributes).forEach(handle => handle())
 
-            if (el._x_ignore) {
-                skip()
-            } else {
-                el._x_inited = true
-            }
+            el._x_ignore && skip()
         })
     })
 }
@@ -106,7 +96,5 @@ export function destroyTree(root, walker = walk) {
     walker(root, el => {
         cleanupAttributes(el)
         cleanupElement(el)
-
-        delete el._x_inited
     })
 }

+ 1 - 0
packages/alpinejs/src/mutation.js

@@ -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

+ 0 - 30
tests/cypress/integration/mutation.spec.js

@@ -136,36 +136,6 @@ test('can pause and queue mutations for later resuming/flushing',
     }
 )
 
-test('add and move element are been initialized',
-    html`
-        <div x-data="{
-            foo: 0,
-            bar: 0,
-            test() {
-                container = document.createElement('div')
-                this.$root.appendChild(container)
-                alpineElement = document.createElement('span')
-                alpineElement.setAttribute('x-data', '{init() {this.bar++}}')
-                alpineElement.setAttribute('x-init', 'foo++')
-                container.appendChild(alpineElement)
-                container.removeChild(alpineElement)
-                container.appendChild(alpineElement)
-            }
-        }">
-            <span id="one" x-text="foo"></span>
-            <span id="two" x-text="bar"></span>
-            <button @click="test">Test</button>
-        </div>
-    `,
-    ({ get }) => {
-        get('span#one').should(haveText('0'))
-        get('span#two').should(haveText('0'))
-        get('button').click()
-        get('span#one').should(haveText('1'))
-        get('span#two').should(haveText('1'))
-    }
-)
-
 test('does not initialise components twice when contained in multiple mutations',
     html`
         <div x-data="{