Performance: Error handling in HTTP calls
MEDIUM IMPACT
This affects the responsiveness and smoothness of the user interface during and after HTTP requests.
import { ref } from 'vue'; const data = ref(null); const error = ref(null); async function fetchData() { try { const response = await fetch('https://api.example.com/data'); if (!response.ok) throw new Error('Network response was not ok'); data.value = await response.json(); error.value = null; } catch (err) { error.value = err.message; } }
fetch('https://api.example.com/data') .then(response => response.json()) .then(data => { this.data = data; }) .catch(error => { alert('Error occurred: ' + error.message); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking alert() in catch | Minimal DOM changes | Triggers reflow after alert dismissed | Blocks paint during alert | [X] Bad |
| Reactive error state update | Updates reactive DOM nodes | Single reflow for error message | Smooth paint without blocking | [OK] Good |