Performance: Why security matters in Vue
HIGH IMPACT
Security issues in Vue apps can cause slowdowns due to extra processing or errors, impacting user experience and interaction speed.
<template>
<div>{{ userInput }}</div>
</template>
<script setup>
const userInput = '<img src=x onerror=alert(1)>'
</script><template> <div v-html="userInput"></div> </template> <script setup> const userInput = '<img src=x onerror=alert(1)>' </script>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Unsafe v-html with raw user input | Adds unpredictable nodes | Multiple reflows if scripts modify DOM | High paint cost due to layout shifts | [X] Bad |
| Safe text interpolation with escaped content | Stable DOM nodes | Single reflow on initial render | Low paint cost, no layout shifts | [OK] Good |