Performance: Revalidation after mutation
MEDIUM IMPACT
This affects how quickly updated data appears on the page after a user changes it, impacting perceived responsiveness and freshness.
import { mutate } from 'swr'; async function handleUpdate() { await fetch('/api/update', { method: 'POST', body: JSON.stringify(data) }); mutate('/api/data', updatedData, false); }
async function handleUpdate() { await fetch('/api/update', { method: 'POST', body: JSON.stringify(data) }); router.refresh(); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Full router.refresh() after mutation | High (full page data reload) | Multiple reflows due to layout recalculation | High paint cost due to full content update | [X] Bad |
| Cache mutation with mutate() after mutation | Low (only updated nodes) | Single reflow or none | Low paint cost with partial update | [OK] Good |