Performance: Why deep reactivity understanding matters
HIGH IMPACT
This affects how efficiently Vue tracks and updates changes in the UI, impacting rendering speed and responsiveness.
const state = reactive({ user: { name: 'Alice', age: 30 } }); // Update nested properties to keep reactivity state.user.name = 'Bob'; state.user.age = 25;
const state = reactive({ user: { name: 'Alice', age: 30 } }); // Directly replacing nested object without deep reactivity state.user = { name: 'Bob', age: 25 };
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Replacing nested objects | Many DOM updates | Multiple reflows | High paint cost | [X] Bad |
| Updating nested properties directly | Minimal DOM updates | Single reflow | Low paint cost | [OK] Good |
| Using shallowReactive for nested data | Missed updates | No reflows but stale UI | No paint cost but poor UX | [X] Bad |
| Using reactive for nested data | Accurate DOM updates | Minimal reflows | Efficient paint | [OK] Good |