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
Reproduction
https://stackblitz.com/edit/vitejs-vite-bvw5gp?file=src%2FApp.vue
System Info
N/A
Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a VueUse issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 4 months ago
- Comments: 24 (19 by maintainers)
Commits related to this issue
- [GYMX-720 GYMX-714] optimize keyboard handling - update deps to fix https://github.com/vueuse/vueuse/issues/3794 via https://github.com/vueuse/vueuse/pull/3815 — committed to FitX/customer-components by webdesignberlin 4 months ago
BTW, it’s not suggested to directly reply under a closed issue, you can create a new one next time.
You can extract the
useStorageoutside the getters like on the top of the file, and use the return value in the getters.I see, what’s the approach to resolve this warning?
At least in my side, I believe returning a
computedWithControlcould be a bad thing for users, just take theuseActiveElementas 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:
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 incomputedWithControldocs helps.I would suggest one of the 2 things which should really solve the issue:
computedWithControlwork with Vue 3.4 new reactivity systemcomputedWithControland 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
computedWithControland 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.cc @Doctor-wu