Performance
SAFE-TS flags Vue template and reactivity patterns that quietly trigger O(n²) work, redundant allocations, or excessive proxy overhead on every render.
In short
- Move list work into
computed: avoid.filter(),.sort(), or linear lookups inside templates andv-for(vue-render-cost). - Avoid accidental deep watches: watch only the specific reactive fields your callback actually reads (
vue-deep-watch). - Use
shallowReffor immutable data: skip deep reactive proxying on readonly objects and arrays (vue-prefer-shallow-ref).
Work in the template runs on every render. Any reactive change re-evaluates template expressions whether their inputs changed or not—filtering a list or running .includes() inside v-for repeats O(n) work per row (vue-render-cost):
✕ Rejectedvue-render-cost
vue
<script setup lang="ts">
type Todo = { readonly id: string; readonly title: string; readonly done: boolean };
const props = defineProps<{ todos: readonly Todo[]; selected: readonly string[] }>();
</script>
<template>
<ul>
<li v-for="todo in props.todos.filter((t) => !t.done)" :key="todo.id" :class="{ selected: props.selected.includes(todo.id) }">
{{ todo.title }}
</li>
</ul>
</template>A computed runs again only when what it reads changes, and a Set finds an id without walking a list:
✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { computed } from "vue";
type Todo = { readonly id: string; readonly title: string; readonly done: boolean };
const props = defineProps<{ todos: readonly Todo[]; selected: readonly string[] }>();
const open = computed(() => props.todos.filter((t) => !t.done));
const selected = computed(() => new Set(props.selected));
</script>
<template>
<ul>
<li v-for="todo in open" :key="todo.id" :class="{ selected: selected.has(todo.id) }">
{{ todo.title }}
</li>
</ul>
</template>Keys. Without a :key, or keyed by position, Vue reuses rows by position: delete the first row and the text typed into its input moves to the next one. Key rows by a stable id from the item (vue-v-for-key), and filter in a computed instead of putting v-if next to v-for (vue-v-if-with-v-for).
Deep reactivity you don't use. ref wraps every nested object in a proxy so it can track changes inside it. Data you only ever replace, like a list loaded from the server, doesn't need that: shallowRef tracks .value alone (vue-prefer-shallow-ref). A watcher on a whole reactive object is deep: it walks the object on every change. Watch the fields you use (vue-deep-watch); a callback that needs the whole object (saving it) can take the value and keep the deep watch:
✕ Rejectedvue-prefer-shallow-refvue-deep-watch
ts
import { reactive, ref, watch } from "vue";
type Product = { readonly id: string; readonly name: string };
export function useCatalog(load: (query: string) => readonly Product[]) {
const products = ref<readonly Product[]>([]);
const filters = reactive({ query: "", page: 1 });
watch(filters, () => {
products.value = load(filters.query);
});
return { products, filters };
}✓ Accepted0 diagnostics
ts
import { reactive, shallowRef, watch } from "vue";
type Product = { readonly id: string; readonly name: string };
export function useCatalog(load: (query: string) => readonly Product[]) {
const products = shallowRef<readonly Product[]>([]);
const filters = reactive({ query: "", page: 1 });
watch(() => filters.query, (query) => {
products.value = load(query);
});
return { products, filters };
}Rules on this page: vue-render-cost, vue-v-for-key, vue-v-if-with-v-for, vue-prefer-shallow-ref, vue-deep-watch