Question presented to candidate:
"When I change cart.qty in a Vue 3 component, the total on screen updates without me calling anything. Explain how Vue knows what to update, and what actually happens between my assignment and the DOM changing."
What a strong answer should cover:
reactive()returns a JavaScript Proxy;ref()wraps a value in an object whose.valuegetter and setter do the same job.- Reading a property inside a running effect calls track, which records "this effect depends on this key". Writing calls trigger, which re-runs only the effects that depend on that key.
- The component render function, every
computedand every watcher are effects; dependencies are collected dynamically on each run, so a branch that was not read is not a dependency. - Writes are batched: the scheduler queues each affected job once and flushes the queue in a microtask, so three synchronous writes cause one render.
- Contrast with Vue 2 (
Object.defineProperty, no tracking of added keys) and mention the 3.4 and 3.5 internal refactors. - Know where the system stops: destructured values, non-proxied built-ins, and identity differences between the proxy and the raw object.
Clarifying questions expected:
- "Do you want the user-facing API, or the internals: track, trigger and the scheduler?"
- "Are we talking about Vue 3 only, or should I contrast it with Vue 2?"
Code / implementation expected: Optional β a 20-line toy track/trigger with a Proxy, or a component that logs how many renders three writes cause.