Performance: Reactivity caveats and limitations
This affects how efficiently the UI updates in response to data changes, impacting interaction responsiveness and visual stability.
const profile = reactive({ name: 'Alice', age: 30 }); const state = reactive({ userProfile: profile }); // Update shallow reactive object directly profile.age = 31;
const state = reactive({ user: { profile: { name: 'Alice', age: 30 } } }); // Updating deeply nested property triggers full deep reactivity state.user.profile.age = 31;
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Deep reactive nested objects | High (many dependencies) | Multiple reflows per update | High paint cost due to frequent updates | [X] Bad |
| Shallow reactive objects with focused updates | Low (few dependencies) | Single reflow per update | Low paint cost | [OK] Good |
| Watcher without deep option on nested data | Missed updates or redundant triggers | Unpredictable reflows | Inconsistent paint | [!] OK |
| Using Vue reactive array methods | Correct dependency tracking | Single reflow per mutation | Consistent paint | [OK] Good |
const state = reactive({ items: ['a', 'b', 'c'] });
state.items[1] = 'x';
console.log(state.items);const obj = reactive({});
obj.newProp = 123;
console.log(obj.newProp);age to a reactive object user and ensure Vue tracks it reactively. Which approach is correct?Pass the test and this pattern moves unknown