Question presented to candidate:
"Forget the basic difference between watch and watchEffect for a moment. When exactly does a watcher callback run relative to the component re-render, what do flush: 'pre', 'post' and 'sync' change, and which watch options and APIs are new in Vue 3.5?"
What a strong answer should cover:
- Writes are batched:
prewatchers (the default) run in the scheduler flush before the component re-renders, so they see the new state but the old DOM. flush: 'post'runs after the DOM patch (alongsideonUpdated), so it can read the updated DOM;watchPostEffectis the shorthand.flush: 'sync'runs synchronously on every write, with no batching;watchSyncEffectis the shorthand. Use it rarely.- New in 3.5:
deepaccepts a number (traversal depth), the handle haspause()/resume(), andonWatcherCleanup()registers cleanup without the third callback argument.getCurrentWatcher()and a basewatchin@vue/reactivitylanded too. once: trueis from 3.4, not 3.5;immediateand booleandeeppredate both.- Know the edges:
onWatcherCleanupmust be called before the firstawait; resuming a paused watcher fires once if the source changed while paused.
Clarifying questions expected:
- "Does the callback need to read the updated DOM, or only the new state?"
- "Is the project on 3.5 already? Some of these options do not exist on 3.4."
Code / implementation expected: Yes — a component with sync, pre and post watchers on the same ref, logging what the DOM shows in each, plus a short script exercising the 3.5 options.