Vue · VUE0028
Keep computed getters pure and synchronous
Flags computed getters that write state, sort or reverse a reactive array in place, start timers, or return a Promise.
vue/reactivity/no-computed-side-effectssrc/rule-packs/vue/rules/vue/no-computed-side-effects.ts Upstream docs Run this rule
pnpm vite-doctor . --framework vue --rules vue/reactivity/no-computed-side-effects
Why it matters
Computed getters are lazy and cached, so side effects inside them run at unpredictable times, .sort() and `.`reverse() reorder the source array in place, and an async getter makes the computed value a Promise instead of the data.
Recommended fix
Keep the getter pure and synchronous: sort a copy, move writes and timers into a watcher or event handler, and load async data into a ref that the computed reads.
Useful links
- Rule reference
- eslint-plugin-vue no-side-effects-in-computed-properties
- eslint-plugin-vue no-async-in-computed-properties
Example
Sort a copy inside computed
Before
<script setup lang="ts">
const items = ref([3, 1, 2])
const sorted = computed(() => items.value.sort())
</script>
After
<script setup lang="ts">
const items = ref([3, 1, 2])
const sorted = computed(() => items.value.toSorted())
</script>