vue-render-cost
Work in the template that repeats on every render: sorting, filtering or reducing a whole list, a lookup in a list inside v-for, or a new Intl formatter.
Why: any change the component reacts to renders it again, and every expression in the template runs again with it, whether its inputs changed or not. A filter there redoes the whole list on each keystroke in an unrelated input. A lookup like selected.includes(id) inside v-for walks selected once per row: 1,000 rows and 1,000 selected ids are a million steps per render. A computed only runs again when what it reads changes, and a Set finds an id in one step. Guide: Vue.
✕ Rejectedvue-render-cost
vue
<script setup lang="ts">
type Order = { readonly id: string; readonly total: number; readonly paid: boolean };
const props = defineProps<{ orders: readonly Order[]; flagged: readonly string[] }>();
</script>
<template>
<p>Unpaid: {{ new Intl.NumberFormat("en", { style: "currency", currency: "EUR" }).format(props.orders.filter((o) => !o.paid).reduce((sum, o) => sum + o.total, 0)) }}</p>
<ul>
<li v-for="order in props.orders" :key="order.id" :class="{ flagged: props.flagged.includes(order.id) }">
{{ order.id }}
</li>
</ul>
</template>✓ Accepted0 diagnostics
vue
<script setup lang="ts">
import { computed } from "vue";
type Order = { readonly id: string; readonly total: number; readonly paid: boolean };
const props = defineProps<{ orders: readonly Order[]; flagged: readonly string[] }>();
const euros = new Intl.NumberFormat("en", { style: "currency", currency: "EUR" });
const unpaid = computed(() => props.orders.filter((o) => !o.paid).reduce((sum, o) => sum + o.total, 0));
const flagged = computed(() => new Set(props.flagged));
</script>
<template>
<p>Unpaid: {{ euros.format(unpaid) }}</p>
<ul>
<li v-for="order in props.orders" :key="order.id" :class="{ flagged: flagged.has(order.id) }">
{{ order.id }}
</li>
</ul>
</template>What it looks for, outside event handlers: sort, toSorted, filter, reduce, reduceRight and flatMap anywhere in the template (including the list of a v-for); includes, indexOf, find, findIndex, some, every and similar inside a v-for, on a list that doesn't come from the loop itself; and new Intl.*(...). (Inside a v-for, a new formatter is reported by hoist-intl.)
A warning in the recommended oxlint preset: on a short list, it's fine.