vue-side-effect-in-render
State changed in a computed getter or while the template renders: an assignment, ++/--, or a method that changes its object (push, sort, reverse, splice, set, delete, ...). Also an async computed getter.
Why: Vue runs getters and templates whenever it decides to, as often as it needs to, expecting them to only read. A getter that changes state changes it at a moment nobody chose; a template that changes state it also reads triggers another render, which changes it again (in development, Vue gives up with "Maximum recursive updates exceeded"). An async getter returns a Promise, not the value. Guide: Vue.
✕ Rejectedvue-side-effect-in-render
vue
<script setup lang="ts">
import { computed, ref } from "vue";
const props = defineProps<{ names: readonly string[] }>();
const reads = ref(0);
const latest = ref<string[]>([]);
const count = computed(() => {
reads.value++;
return props.names.length;
});
</script>
<template>
<p>{{ count }} names, newest first: {{ latest.reverse().join(", ") }}</p>
</template>latest.reverse() reverses the array in place, on every render.
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { computed, ref } from "vue";
const props = defineProps<{ names: readonly string[] }>();
const latest = ref<string[]>([]);
const count = computed(() => props.names.length);
const newestFirst = computed(() => [...latest.value].reverse().join(", "));
</script>
<template>
<p>{{ count }} names, newest first: {{ newestFirst }}</p>
</template>Allowed: changing what the getter created itself ([...list].sort(), a local array), the setter of a writable computed({ get, set }), and event handlers in the template, which run when the event happens, not while rendering.