Question presented to candidate: "Tell me about the reactivity gotchas you have actually hit in Vue 3. For each one, what is the symptom, why does it happen in terms of how reactivity works, and how do you fix it?"
What a strong answer should cover:
- Values copied out of the proxy: destructuring a reactive object, passing
state.countinto a composable, spreading. Fix withtoRefs,toRef, getters andtoValue. - Objects that are never proxied:
Dateand other built-ins, frozen objects,markRaw, and contents of ashallowRef. Class instances with#privatefields throw aTypeErrorthrough a Proxy. - Reads that are not tracked: after an
awaitinwatchEffectorcomputed, or outside any effect. - Identity and unwrapping: the proxy is not
===the raw object; refs in reactive arrays and Maps are not unwrapped;watchon a reactive object gives the same object as new and old value. - Compile-time and runtime guard rails: passing a destructured prop straight to
watch()is a compiler error in 3.5; watchers that write each other's sources end in "Maximum recursive updates exceeded". - The Vue 2 caveats (adding keys,
arr[i] = x,Vue.set) no longer apply in Vue 3.
Clarifying questions expected:
- "Composition API with
<script setup>, or Options API? Some caveats only exist in one." - "Are there large or third-party objects in state? That changes the advice."
Code / implementation expected: Yes โ a component where a broken and a fixed version of each caveat render side by side.