Kaynağa Gözat

Merge branch 'master' into bug/nested-proxies

Caleb Porzio 5 yıl önce
ebeveyn
işleme
107e452c9b
4 değiştirilmiş dosya ile 28 ekleme ve 3 silme
  1. 1 1
      README.md
  2. 1 1
      package.json
  3. 1 1
      src/index.js
  4. 25 0
      test/mutations.spec.js

+ 1 - 1
README.md

@@ -14,7 +14,7 @@ Think of it like [Tailwind](https://tailwindcss.com/) for JavaScript.
 
 **From CDN:** Add the following script to the end of your `<head>` section.
 ```html
-<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v1.9.5/dist/alpine.js" defer></script>
+<script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v1.9.6/dist/alpine.js" defer></script>
 ```
 
 That's it. It will initialize itself.

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
   "main": "dist/alpine.js",
   "name": "alpinejs",
-  "version": "1.9.5",
+  "version": "1.9.6",
   "repository": {
     "type": "git",
     "url": "git://github.com/alpinejs/alpine.git"

+ 1 - 1
src/index.js

@@ -60,7 +60,7 @@ const Alpine = {
 
                         // Discard any changes happening within an existing component.
                         // They will take care of themselves.
-                        if (node.parentElement.closest('[x-data]')) return
+                        if (node.parentElement && node.parentElement.closest('[x-data]')) return
 
                         this.discoverUninitializedComponents((el) => {
                             this.initializeComponent(el)

+ 25 - 0
test/mutations.spec.js

@@ -0,0 +1,25 @@
+import Alpine from 'alpinejs'
+
+test('catch disconnected nodes that were used as targets for any mutations', async () => {
+    const runObservers = []
+
+    global.MutationObserver = class {
+        constructor(callback) { runObservers.push(callback) }
+        observe() {}
+    }
+
+    document.body.innerHTML = `
+        <div x-data="{}">
+        </div>
+    `
+
+    Alpine.start()
+
+    runObservers.forEach(cb => cb([
+        {
+            target: document.createElement('div'),
+            type: 'childList',
+            addedNodes: [ document.createElement('div') ],
+        }
+    ]))
+})