Browse Source

Stop proxy to trigger a TypeError when there is an assignment in strict mode and reactivity is suspended

Simone Todaro 5 years ago
parent
commit
b0a80b5a56
4 changed files with 31 additions and 1 deletions
  1. 0 0
      dist/alpine.js
  2. 0 0
      dist/alpine.js.map
  3. 1 1
      src/component.js
  4. 30 0
      test/strict-mode.spec.js

File diff suppressed because it is too large
+ 0 - 0
dist/alpine.js


File diff suppressed because it is too large
+ 0 - 0
dist/alpine.js.map


+ 1 - 1
src/component.js

@@ -76,7 +76,7 @@ export default class Component {
                 const setWasSuccessful = Reflect.set(obj, property, value)
 
                 // Don't react to data changes for cases like the `x-created` hook.
-                if (self.pauseReactivity) return
+                if (self.pauseReactivity) return setWasSuccessful
 
                 debounce(() => {
                     self.updateElements(self.$el)

+ 30 - 0
test/strict-mode.spec.js

@@ -0,0 +1,30 @@
+import Alpine from 'alpinejs'
+import { wait } from '@testing-library/dom'
+
+global.MutationObserver = class {
+    observe() {}
+}
+
+test('Proxy does not error in strict mode when reactivity is suspended', async () => {
+    "use strict"
+
+    global.statCounter = function () {
+        return {
+            count: 0,
+            init() {
+                this.count = 1200;
+            }
+        }
+    }
+    document.body.innerHTML = `
+        <div class="my-48">
+            <div x-data="statCounter()" x-init="init()">
+                <span x-text="count"></span>
+            </div>
+        </div>
+    `
+
+    Alpine.start()
+
+    await wait(() => { expect(document.querySelector('span').innerText).toEqual(1200) })
+})

Some files were not shown because too many files changed in this diff