Question presented to candidate:
"Our dashboard has a profile panel and a stats panel, each loading its own data, and the page flickers through two spinners. Someone suggested Vue's <Suspense>. What is it, what can it wait for, and what would you need to handle around it?"
What a strong answer should cover:
<Suspense>is a built-in component that coordinates async dependencies in the subtree below it and renders one#fallbackuntil all of them are ready, then the#defaultslot.- The two kinds of dependency: components with an async
setup()(including<script setup>with top-levelawait) and async components fromdefineAsyncComponent. - Events:
pending,fallback,resolve. - Suspense does not handle errors: a rejected setup must be caught with
onErrorCapturedorapp.config.errorHandler. - On the server,
renderToStringwaits for the async setup and sends the resolved HTML, not the fallback. - It is still marked experimental: the Vue 3.5.44 runtime prints that on first use and the docs carry an "Experimental Feature" warning.
Clarifying questions expected:
- "Do both panels need to appear together, or can each show as soon as it is ready?"
- "Is the app server-rendered?"
Code / implementation expected: Yes β a <Suspense> around two async children with a fallback, plus error handling.