Performance: Error handling in load
MEDIUM IMPACT
This affects page load speed and user experience by controlling how errors during data fetching impact rendering and interactivity.
export async function load({ fetch }) { try { const res = await fetch('/api/data'); if (!res.ok) { return { data: null, error: 'Failed to load data' }; } const data = await res.json(); return { data }; } catch (e) { return { data: null, error: 'Network error' }; } }
export async function load({ fetch }) { const res = await fetch('/api/data'); if (!res.ok) { throw new Error('Failed to load data'); } const data = await res.json(); return { data }; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Throw error without fallback | Minimal DOM nodes but blocks rendering | 0 reflows but blocks layout | Delays paint until error handled | [X] Bad |
| Catch error and return fallback data | Adds error message nodes | 1 reflow for error UI | Paints fallback UI quickly | [OK] Good |