Caleb Porzio 2 years ago
parent
commit
f3616c8706
1 changed files with 13 additions and 2 deletions
  1. 13 2
      packages/alpinejs/src/directives/x-modelable.js

+ 13 - 2
packages/alpinejs/src/directives/x-modelable.js

@@ -22,7 +22,18 @@ directive('modelable', (el, { expression }, { effect, evaluateLater }) => {
         let outerGet = el._x_model.get
         let outerGet = el._x_model.get
         let outerSet = el._x_model.set
         let outerSet = el._x_model.set
 
 
-        effect(() => innerSet(outerGet()))
-        effect(() => outerSet(innerGet()))
+        effect(() => {
+            // Putting this operation in a microtask so that
+            // it doesn't get tracked in the effect:
+            let value = outerGet()
+            queueMicrotask(() => innerSet(value))
+        })
+
+        effect(() => {
+            // Putting this operation in a microtask so that
+            // it doesn't get tracked in the effect:
+            let value = innerGet()
+            queueMicrotask(() => outerSet(value))
+        })
     })
     })
 })
 })