vueuse: [Bug report] computedWithControl is triggering "Computed is still dirty after getter evaluation" warning

Describe the bug

Related issue: https://github.com/vuejs/core/issues/10341

computedWithControl will trigger the warning in vue 3.4.19:

[Vue warn] Computed is still dirty after getter evaluation, likely because a computed is mutating its own dependency in its getter. State mutations in computed getters should be avoided.  Check the docs for more details: https://vuejs.org/guide/essentials/computed.html#getters-should-be-side-effect-free
image image

Reproduction

https://stackblitz.com/edit/vitejs-vite-bvw5gp?file=src%2FApp.vue

System Info

N/A

Used Package Manager

npm

Validations

About this issue

  • Original URL
  • State: closed
  • Created 4 months ago
  • Comments: 24 (19 by maintainers)

Commits related to this issue

Most upvoted comments

BTW, it’s not suggested to directly reply under a closed issue, you can create a new one next time.

You can extract the useStorage outside the getters like on the top of the file, and use the return value in the getters.

  const isLoggedInRef = useStorage('isLoggedIn')
  ...
  getters: {
    isLoggedIn: () => isLoggedInRef.value
  }

CleanShot 2024-02-21 at 10 24 33@2x In fact, getters in Pinia is a computed as well, so it will cause that warning.

I see, what’s the approach to resolve this warning?

At least in my side, I believe returning a computedWithControl could be a bad thing for users, just take the useActiveElement as example, we can definitely return a standard computed so that users can generate other state with computed.😉 Can this be considered, and do you think a full check in all apis is helpful?

I think mark this function is not a computed will be helpful, thanks for your suggestions!

I suggest not closing this issue too casually. it’s weird to say:

computedWithControl is not a computed under the hood.

Then why a name with computedWithControl? There are people reporting the same problem with VueUse functions (see https://github.com/vueuse/vueuse/issues/3774#issuecomment-1945839213). I don’t think add a warning somewhere in computedWithControl docs helps.

I would suggest one of the 2 things which should really solve the issue:

  • try to make computedWithControl work with Vue 3.4 new reactivity system
  • deprecate computedWithControl and any other api with /** @deprecated */ which may confuse the users, and give them new name to better describe them and maybe warnings in jsdocs too.

As long as computedWithControl and things like this is returned in any VueUse functions, then it will probably be misused in user cases. You can not expect users to special handle them.