Question presented to candidate:
"Our modal is rendered deep inside a card that has overflow: hidden and its own z-index, so the modal gets clipped. A teammate suggested <Teleport>. Explain what Teleport does, what stays the same for the component, and what can go wrong."
What a strong answer should cover:
<Teleport to="body">moves the rendered DOM of its content to another place in the document, while the content stays in the same component tree.- Props, emits, reactive state,
provide/injectand event handlers keep working, because those follow the component tree, not the DOM. - The
totarget is a CSS selector or element that must exist when the Teleport mounts;disabledrenders the content in place instead (for example on mobile). defer(Vue 3.5+) resolves the target after the current render, so it can point at an element rendered later by the same app.- Typical uses: modals, toasts, tooltips and dropdowns that must escape
overflow,z-indexstacking contexts ortransformed ancestors. - In SSR, teleported HTML is returned separately in the render context and must be injected into the page by the server.
Clarifying questions expected:
- "Is the target outside the Vue app, such as a
#modalsdiv inindex.html, or rendered by the app?" - "Is this app server-rendered?"
Code / implementation expected: Yes β a modal teleported to body, ideally with disabled or defer shown.