[{"id":"vueadvanced-001","courseId":"vue-advanced","domain":"reactivity","topic":"Sync watchers without batching","prompt":"A component watches a reactive array with flush: 'sync'. A loop pushes 1000 items into it. How many times does the watcher callback run?","hint":"Think about whether a sync watcher waits for the mutations to finish.","explain":"Watchers can batch: a burst of changes may collapse into one callback call. Each watcher picks a flush timing, and that choice decides whether it waits for a batch.","source":"https://vuejs.org/guide/essentials/watchers.html#sync-watchers","interaction":{"type":"single"},"options":[{"id":"a","text":"1000 times, once per push","why":"A sync watcher has no batching, so every mutation it detects triggers a callback call."},{"id":"b","text":"Once, after the loop finishes","whyNot":"That is the default batched behavior, which a sync watcher skips."},{"id":"c","text":"Once, just before the next component render","whyNot":"That is the default pre timing, which batches changes; sync watchers do not batch at all."},{"id":"d","text":"Only once, on the first push","whyNot":"Nothing skips later mutations; the callback fires for each change it detects."}],"answer":"a","explanation":"Sync watchers (flush: 'sync') run on each reactive mutation with no batching, so a loop of 1000 pushes fires the callback 1000 times.","concept":"Sync watchers (flush: 'sync') run on each reactive mutation with no batching, so a loop of 1000 pushes fires the callback 1000 times.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"const items = reactive([])\nwatch(items, () => {\n  console.log('changed')\n}, { flush: 'sync' })\n\nfor (let i = 0; i < 1000; i++) {\n  items.push(i)\n}","takeaways":["Avoid flush: 'sync' on arrays or other data that is mutated many times in a row."]},{"id":"vueadvanced-002","courseId":"vue-advanced","domain":"reactivity","topic":"Watcher flush order","prompt":"A component has a watcher using the default flush timing and another using flush: 'post'. Both watch the same state. Put these steps in the order Vue runs them after a reactive change.","hint":"Ask which DOM the default watcher callback is allowed to see.","explain":"Vue runs a component's update work in stages, so watcher callbacks can land before or after the owner's DOM is patched. The flush option controls which stage a watcher uses.","source":"https://vuejs.org/guide/essentials/watchers.html#callback-flush-timing","interaction":{"type":"sort","items":[{"text":"Parent component updates (if any)","why":"A default watcher callback waits until any parent component updates have finished."},{"text":"Default watcher callback (flush: 'pre')","why":"Runs before the owner's DOM is updated, so the DOM it reads is still in its pre-update state."},{"text":"Owner component DOM updates","why":"Vue patches the owner's DOM after the default watcher callbacks have run."},{"text":"Post watcher callback (flush: 'post')","why":"Runs after Vue has updated the owner's DOM, so the DOM it reads is current."}]},"options":[],"answer":"o:abcd","explanation":"Default (pre) watchers run after parent updates and before the owner's DOM updates; flush: 'post' watchers run after the owner's DOM has been updated.","concept":"Default (pre) watchers run after parent updates and before the owner's DOM updates; flush: 'post' watchers run after the owner's DOM has been updated.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Use flush: 'post' when a watcher callback needs to read the owner's updated DOM."]},{"id":"vueadvanced-003","courseId":"vue-advanced","domain":"reactivity","topic":"effectScope disposes effects","prompt":"A library creates a scope with effectScope(), then calls scope.run() to create a computed and a watchEffect. Later the app calls scope.stop(). What happens to those effects?","hint":"Think about what a scope is for: grouping effects so they can be handled together.","explain":"An effect scope captures the computeds and watchers created inside its run() call. Stopping the scope is one action that covers every effect it captured.","source":"https://vuejs.org/api/reactivity-advanced.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Both are disposed and stop reacting to changes","why":"scope.stop() disposes all the computed and watcher effects captured in the scope."},{"id":"b","text":"Both keep running until the app's component unmounts","whyNot":"Effect scopes are not tied to components; stop() disposes the scope's effects directly."},{"id":"c","text":"Only the watchEffect stops; the computed keeps running","whyNot":"Computed effects are captured too, so stop() disposes the scope's computeds as well as its watchers."},{"id":"d","text":"Only effects created with a stop handle are disposed","whyNot":"Creating effects inside run() is enough; each one does not need its own handle for stop() to dispose it."}],"answer":"a","explanation":"An effect scope captures the computed and watcher effects created inside scope.run(), and scope.stop() disposes all of them together.","concept":"An effect scope captures the computed and watcher effects created inside scope.run(), and scope.stop() disposes all of them together.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"const count = ref(0)\nconst scope = effectScope()\nscope.run(() => {\n  const doubled = computed(() =>\n    count.value * 2\n  )\n  watchEffect(() => {\n    console.log(doubled.value)\n  })\n})\nscope.stop()","takeaways":["Wrap effects in scope.run() so one scope.stop() can dispose them together."]},{"id":"vueadvanced-004","courseId":"vue-advanced","domain":"reactivity","topic":"onScopeDispose outside components","prompt":"In Vue 3.5, calling onScopeDispose(fn) at the top level of a module, with no active effect scope, throws an error and stops the app.","hint":"Think about whether Vue reports this misuse as an error or as a warning.","explain":"onScopeDispose attaches a callback to the active effect scope, which runs when that scope stops. Calling it with no active scope leaves it nothing to attach to, and Vue reports that in a specific way.","source":"https://vuejs.org/api/reactivity-advanced.html","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"Vue prints a warning instead of throwing an error for this call."},{"id":"b","text":"False","why":"Vue only warns. In 3.5+, passing true as the second argument suppresses that warning."}],"answer":"b","explanation":"onScopeDispose with no active scope triggers a warning, not an error; in 3.5+ passing true as the second argument suppresses the warning.","concept":"onScopeDispose with no active scope triggers a warning, not an error; in 3.5+ passing true as the second argument suppresses the warning.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Call onScopeDispose inside a scope or component; outside one it only warns."]},{"id":"vueadvanced-005","courseId":"vue-advanced","domain":"reactivity","topic":"readonly() is deep","prompt":"A config object is wrapped with readonly(). Later, code runs config.db.host = 'backup'. What happens?","hint":"Ask how far the readonly conversion reaches into nested objects.","explain":"readonly() wraps nested objects as it reaches them, so properties reached through it are read-only as well. A different variant only protects the top level of an object.","source":"https://vuejs.org/api/reactivity-core.html","interaction":{"type":"single"},"options":[{"id":"a","text":"Vue warns and the write fails, so host stays 'primary'","why":"readonly() is deep: nested properties reached through it are readonly too, so the write fails with a warning."},{"id":"b","text":"The write succeeds, because only top-level properties are readonly","whyNot":"That describes shallowReadonly(). readonly() converts nested objects as well."},{"id":"c","text":"The write throws a TypeError and stops the app","whyNot":"Vue reports the blocked write as a warning; the write is refused without throwing."},{"id":"d","text":"The write succeeds and triggers a re-render","whyNot":"Readonly proxies block writes to nested properties just as they block writes at the top level."}],"answer":"a","explanation":"readonly() is deep: nested objects reached through it are readonly too, so writing to a nested property fails with a warning.","concept":"readonly() is deep: nested objects reached through it are readonly too, so writing to a nested property fails with a warning.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"const config = readonly({\n  db: { host: 'primary' }\n})\nconfig.db.host = 'backup'","takeaways":["Use shallowReadonly() only when nested objects should stay writable on purpose."]}]