0
0
Vueframework~10 mins

Reactivity caveats and limitations in Vue - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Reactivity caveats and limitations
Start with reactive data
Change reactive property
Vue tracks dependency
Trigger update
Component re-renders
Check for caveats
Works
Manual fix or workaround
This flow shows how Vue tracks reactive data changes and updates components, but also highlights where limitations require manual handling.
Execution Sample
Vue
import { reactive, effect } from 'vue'

const state = reactive({ count: 0 })

effect(() => {
  console.log(state.count)
})

state.count = 1
This code creates a reactive object and an effect that logs the count whenever it changes.
Execution Table
StepActionReactive PropertyEffect TriggeredConsole Output
1Create reactive objectcount = 0No
2Register effectcount = 0Yes (initial run)0
3Update count to 1count = 1Yes1
4Update nested property (not reactive)nested.prop = 2No
5Add new property dynamicallynewProp = 3No
6Manually trigger update after adding newPropnewProp = 3Yes3
💡 Reactivity stops automatically tracking new or nested properties unless handled explicitly.
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 5After Step 6
state.count01111
state.nested.propundefinedundefined222
state.newPropundefinedundefinedundefined33
Key Moments - 3 Insights
Why doesn't Vue react to adding a new property dynamically?
Vue's reactivity system tracks properties present when the reactive object is created. Adding new properties later (see step 5 in execution_table) is not detected automatically, so no effect triggers.
Why doesn't changing a nested property trigger reactivity?
If nested objects are not reactive themselves, Vue won't track changes inside them (step 4). You must make nested objects reactive explicitly to track their changes.
How can we make Vue react to new properties added after creation?
You can use direct property assignment or reassign a tracked property to trigger updates manually (step 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the effect first log '1'?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Check the 'Console Output' column for when '1' appears.
According to variable_tracker, what is the value of 'state.newProp' after step 4?
Aundefined
B3
C2
D0
💡 Hint
Look at the 'state.newProp' row under 'After Step 4' column.
If we want Vue to react to 'newProp' added dynamically, what must we do according to the execution flow?
ARemove the reactive wrapper
BNothing, Vue tracks all changes automatically
CManually trigger update or use direct assignment
DOnly update existing properties
💡 Hint
Refer to step 6 in execution_table and key_moments about manual updates.
Concept Snapshot
Vue reactivity tracks properties present at reactive object creation.
Adding new properties later is NOT reactive automatically.
Nested objects must be reactive to track inner changes.
Use direct assignment or manual triggers to update new properties.
Effects run when tracked reactive properties change.
Full Transcript
This visual execution shows Vue's reactivity system starting with a reactive object containing a count property. An effect logs the count whenever it changes. When count updates from 0 to 1, the effect triggers and logs '1'. However, adding new properties or changing nested properties does not trigger effects automatically because Vue only tracks properties present at creation and nested objects must be reactive themselves. To handle new properties, manual triggers or Vue.set are needed. This helps beginners understand where Vue's reactivity works automatically and where manual intervention is required.