Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use watchEffect should pauseTracking with array #12565

Closed
okbug opened this issue Jun 20, 2022 · 2 comments
Closed

use watchEffect should pauseTracking with array #12565

okbug opened this issue Jun 20, 2022 · 2 comments
Labels

Comments

@okbug
Copy link

okbug commented Jun 20, 2022

Version

2.7.0-beta.3

Reproduction link

codesandbox.io

Steps to reproduce

pauseTracking with array length when length-altering mutaion

What is expected?

the first demo in Vue3 can show the [ 1, 2 ]
but in Vue2.7.0-beta.3 it shows [ 1, 2, 1, 2 ]

In the second demo will make page stop running.
it looks like vuejs/core#2137

What is actually happening?

not same result and page stop running

@okbug
Copy link
Author

okbug commented Jun 20, 2022

the code looks like

<div id="demo">
        {{ arr }}
      </div>    

// it use vue2.7.0-beta3
<script src="../../dist/vue.min.js"></script>

<script>
const { ref, watchEffect, watch } = Vue
new Vue({
  setup() {
    const arr = ref([])
    watchEffect(() => {
        arr.value.push(1)
    })

    watchEffect(() => {
        arr.value.push(2)
    })

    return {
        arr
    }
  }
}).$mount('#demo')
</script>


<script>
    const arr = ref([])

    watchEffect(() => {
        arr.value.push(1)
    })
    watchEffect(() => {
        arr.value.push(2)
    })

    console.log(arr.value)
</script>

@yyx990803 yyx990803 added the 2.7 label Jun 21, 2022
@yyx990803
Copy link
Member

Unfortunately this is a limitation of Vue 2's reactivity system. Array mutation methods work by triggering updates of effects that tracks the array itself. There's no way to fix this.

@yyx990803 yyx990803 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants