[{"id":"viteintermediate-001","courseId":"vite-intermediate","domain":"dev-server-and-hmr","topic":"import.meta.hot.accept","prompt":"A module should accept its own hot updates. Vite checks the module's source text before running it, so the call must be written in a specific way. Which form works?","hint":"Vite reads the source text to decide whether to enable HMR for a module.","explain":"Vite decides whether a module can take hot updates by reading its source text ahead of time. Consider how strictly that reading has to match the call.","source":"https://vite.dev/guide/api-hmr","interaction":{"type":"single"},"options":[{"id":"a","text":"import.meta.hot.accept( with the parenthesis directly after accept","why":"Vite requires that exact spelling, because its static analysis looks for it in the source."},{"id":"b","text":"import.meta.hot.accept ( with a space before the parenthesis","whyNot":"The check is whitespace-sensitive, so the space breaks the match and the module will not accept updates."},{"id":"c","text":"module.hot.accept() written the way webpack does it","whyNot":"Vite's HMR API lives on import.meta.hot, so a module.hot call is not recognized."},{"id":"d","text":"A comment near the top that says the module accepts updates","whyNot":"Vite only recognizes the real call in the source; a comment describing it does not enable updates."}],"answer":"a","explanation":"Vite's HMR static analysis only enables a module's hot updates when import.meta.hot.accept( appears in the source, with no whitespace before the parenthesis.","concept":"Vite's HMR static analysis only enables a module's hot updates when import.meta.hot.accept( appears in the source, with no whitespace before the parenthesis.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Self-accepting modules must call import.meta.hot.accept( in exactly that form, because Vite scans for it."]},{"id":"viteintermediate-002","courseId":"vite-intermediate","domain":"dev-server-and-hmr","topic":"import.meta.hot.dispose cleanup","prompt":"A module starts a timer when it loads. After each hot update, the replaced copy's timer keeps firing next to the new one. Which hook is meant for cleaning up such side effects?","hint":"Compare the hooks that handle an update with the one that runs when a module leaves the page.","explain":"A module can run setup code that outlives one version of itself during development. Consider which hook lets the next version tidy up what an earlier version left running.","source":"https://vite.dev/guide/api-hmr","interaction":{"type":"single"},"options":[{"id":"a","text":"import.meta.hot.dispose(cb), which cleans up side effects created by the copy being replaced","why":"dispose is documented for cleaning up persistent side effects created by the updated copy."},{"id":"b","text":"import.meta.hot.prune(cb), which runs on every hot update of the module","whyNot":"prune runs when the module is no longer imported on the page, not on each update."},{"id":"c","text":"import.meta.hot.decline(), which stops the timer from being created","whyNot":"decline is currently a noop kept for backward compatibility, so it does nothing."},{"id":"d","text":"Storing the timer id in import.meta.hot.data, which Vite clears on each update","whyNot":"hot.data persists across instances; Vite clears it only after a pruned module's callbacks finish."}],"answer":"a","explanation":"A self-accepting module uses import.meta.hot.dispose to clean up persistent side effects created by its updated copy, such as a timer.","concept":"A self-accepting module uses import.meta.hot.dispose to clean up persistent side effects created by its updated copy, such as a timer.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Use hot.dispose to undo side effects of the old copy; hot.prune is for removal from the page."]},{"id":"viteintermediate-003","courseId":"vite-intermediate","domain":"dev-server-and-hmr","topic":"import.meta.hot.data persistence","prompt":"A module writes to import.meta.hot.data, is pruned from the page, and is later imported again. Put these stages of the data object's life in order.","hint":"Ask which stage can only happen once the module has left the page.","explain":"Some state can be attached to a module so it outlives one version of its code during development. Think about when that state is thrown away, and what the next load of the module can see.","source":"https://vite.dev/guide/api-hmr","interaction":{"type":"sort","items":[{"text":"A module instance writes properties onto import.meta.hot.data while it runs.","why":"Values written during execution are what the next instance will find."},{"text":"The module is pruned, and its dispose and prune callbacks receive the data object.","why":"Callbacks get the current data only once the module is leaving the page."},{"text":"Vite clears the data object after those callbacks complete.","why":"Clearing waits until the callbacks are done, so they can still read the data."},{"text":"The module is imported again and gets a new empty data object.","why":"Once cleared, nothing carries over, so the next import starts from an empty object."}]},"options":[],"answer":"o:abcd","explanation":"When a module is pruned, its dispose and prune callbacks see the current data; Vite clears the data after they finish, so a later import starts empty.","concept":"When a module is pruned, its dispose and prune callbacks see the current data; Vite clears the data after they finish, so a later import starts empty.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["hot.data survives updates but is cleared once a pruned module's callbacks finish."]},{"id":"viteintermediate-004","courseId":"vite-intermediate","domain":"dev-server-and-hmr","topic":"import.meta.hot.invalidate","prompt":"A self-accepting module finds at runtime that it cannot apply an update. Which TWO statements about import.meta.hot.invalidate() are correct?","hint":"Think about where the update goes after the module refuses it, and what the module must still register.","explain":"Hot updates normally stop at the first module that handles them. A module can change its mind partway through an update, and the update system's bookkeeping for each module decides what follows.","source":"https://vite.dev/guide/api-hmr","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"The HMR server invalidates the module's importers, as if the caller were not self-accepting.","why":"The update is pushed up to the modules that import the caller, which is the documented effect of invalidate."},{"id":"b","text":"Call import.meta.hot.accept even if you call invalidate right after, or the client stops listening for changes.","why":"Without accept, the HMR client does not keep listening for later changes to that module."},{"id":"c","text":"It reloads the whole page at once and skips the module's importers.","whyNot":"invalidate is meant to pass the update up to importers, not to skip them."},{"id":"d","text":"Calling it makes accept unnecessary, because invalidate also registers the module for future updates.","whyNot":"The docs say to always call accept, since invalidate alone does not keep the client listening."},{"id":"e","text":"It logs the message only in the terminal, never in the browser console.","whyNot":"The message appears in both the browser console and the terminal."},{"id":"f","text":"hot.decline() is the recommended way to mark a module as not hot-updatable.","whyNot":"decline is a noop kept for compatibility; invalidate is the documented choice for that."}],"answer":"ab","explanation":"import.meta.hot.invalidate() makes the HMR server invalidate the caller's importers, as if it were not self-accepting; the module should still call accept so the client keeps listening.","concept":"import.meta.hot.invalidate() makes the HMR server invalidate the caller's importers, as if it were not self-accepting; the module should still call accept so the client keeps listening.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["invalidate() hands an update up to importers; keep calling accept so future updates still arrive."]},{"id":"viteintermediate-005","courseId":"vite-intermediate","domain":"dev-server-and-hmr","topic":"HMR error overlay toggle","prompt":"Setting server.hmr.overlay to false turns off the dev server's error overlay.","hint":"Consider which setting in the HMR section controls how errors are displayed.","explain":"The dev server can show errors as a panel inside the browser page. A setting in the HMR section decides whether that panel appears.","source":"https://vite.dev/config/server-options","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","why":"The docs say to set server.hmr.overlay to false to disable the server error overlay."},{"id":"b","text":"False","whyNot":"The docs name this exact setting as the way to disable the overlay, so the statement holds."}],"answer":"a","explanation":"Setting server.hmr.overlay to false disables the server error overlay.","concept":"Setting server.hmr.overlay to false disables the server error overlay.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["server.hmr.overlay: false turns off the in-browser error overlay."]}]