Question presented to candidate:
"What do v-once and v-memo do? Walk me through how the compiled render function differs for each, and tell me when v-memo is worth using and how it can bite you."
What a strong answer should cover:
v-oncerenders an element or component once; later renders reuse the cached VNode, so it never updates even if its data changes.v-memo="[a, b]"caches a subtree and reuses it while every value in the array is unchanged;v-memo="[]"behaves likev-once.- Compiled output:
v-oncebecomes a_cache[i] || (...)expression withsetBlockTracking(-1);v-memobecomes_withMemo(deps, render, _cache, i); on av-forit becomes an inline_isMemoSamecheck per item, also comparing thekey. - A cache hit skips creating the VNodes and diffing them, not just DOM updates.
- Main use: large
v-forlists where only a few rows change (such as the selected row); the dependency array must include everything that should cause an update. - Pitfalls: stale UI from missing dependencies,
v-memoplaced inside av-forinstead of on it, and both directives being ignored during SSR.
Clarifying questions expected:
- "How large is the list, and what changes between renders?"
- "Has profiling shown the render function itself as the bottleneck?"
Code / implementation expected: Yes β compiled output for each directive, or a list with v-memo keyed on selection.