Question presented to candidate:
"You are reviewing a Vue 3 codebase that uses readonly, markRaw and toRaw in various places. For each one, tell me a situation where it is the right tool, and a situation where using it would be a mistake."
What a strong answer should cover:
readonly: expose state from a composable, store orprovideso consumers can read and react but must call actions to change it. Not for immutability, not in hot paths.markRaw: third-party instances (map, chart, editor, SDK clients), classes with#privatefields, component definitions held in state, large static config. Apply it at creation.toRaw: hand plain data to code outside Vue (structuredClone,postMessage, IndexedDB, libraries doing identity checks), or read large data without proxy overhead in an event handler.- Mistakes: writing through
toRaw(no re-render),markRawon data the UI edits, treatingreadonlyas a security boundary. - Related tools:
shallowRefas an alternative tomarkRawfor a slot that is replaced as a whole. - Knowing the dev warning Vue prints when a component is made reactive.
Clarifying questions expected:
- "Who owns this state, and who is allowed to change it?"
- "Does this object come from a library that does its own change tracking?"
Code / implementation expected: Optional β a small screen using all three, or a review of where each belongs.