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

watchEffect getter work problem #388

Closed
WARJY opened this issue Jun 19, 2020 · 6 comments · Fixed by #389
Closed

watchEffect getter work problem #388

WARJY opened this issue Jun 19, 2020 · 6 comments · Fixed by #389
Labels

Comments

@WARJY
Copy link

WARJY commented Jun 19, 2020

const data = ref([1,1,1,1,1])
const data2 = ref([])

watchEffect(()=>{
    data2.value = data.value.slice(1,1)
},{
    flush: "sync"
})
vue.runtime.esm.js?2b0e:1888 RangeError: Maximum call stack size exceeded
    at RegExp.[Symbol.replace] (<anonymous>)
    at String.replace (<anonymous>)
    at classify (vue.runtime.esm.js?2b0e:610)
    at formatComponentName (vue.runtime.esm.js?2b0e:648)
    at eval (vue.runtime.esm.js?2b0e:685)
    at Array.map (<anonymous>)
    at generateComponentTrace (vue.runtime.esm.js?2b0e:683)
    at warn (vue.runtime.esm.js?2b0e:614)
    at logError (vue.runtime.esm.js?2b0e:1884)
    at globalHandleError (vue.runtime.esm.js?2b0e:1879)

when watchEffect getter function include some function who return a anonymous variable(such as Array.slice),it will cause a infinity loop

@posva
Copy link
Member

posva commented Jun 19, 2020

This is expected as you are modifying the data inside of the function that watches it. Use a watch (https://composition-api.vuejs.org/api.html#watch) instead to control what should be observed

@posva posva closed this as completed Jun 19, 2020
@WARJY
Copy link
Author

WARJY commented Jun 19, 2020

as i know , slice will not modify the source array , and if i use it this way, it will work

const data = ref([1,1,1,1,1])
const data2 = ref([])

watchEffect(()=>{
    data2.value[0] = data.value[0]
},{
    flush: "sync"
})

and i'm confused about when to use watchEffect and when to use watch

@posva
Copy link
Member

posva commented Jun 19, 2020

Ah, I read splice

@posva posva reopened this Jun 19, 2020
@WARJY
Copy link
Author

WARJY commented Jun 19, 2020

Ah, I read splice

first time commit issue, XD, it feels good to commucation with developer ⁄(⁄ ⁄ ⁄ω⁄ ⁄ ⁄)⁄

@pikax
Copy link
Member

pikax commented Jun 19, 2020

Thank you for raising it

Looking into this, as for now I recommend using watch until this is fixed :)

@WARJY
Copy link
Author

WARJY commented Jun 19, 2020

Thank you for raising it

Looking into this, as for now I recommend using watch until this is fixed :)

okkkkkkk,XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants