Question presented to candidate:
"We use <style scoped> everywhere, yet a .title rule in a parent still changed a child component's root, and our attempt to restyle a third-party component's inner element did nothing. Explain how scoped styles actually work, and how you would fix both situations."
What a strong answer should cover:
<style scoped>is a compile-time transform: every element the component renders gets adata-v-<hash>attribute, and every selector gets[data-v-<hash>]added to its last compound selector.- A child component's root element carries both the parent's and the child's attribute, so parent rules can reach it (by design, for layout).
- To reach inside a child, use
:deep(.x); to style slot content from the component that renders the slot,:slotted(); to escape scoping for one rule,:global(). - Content from
v-htmland multi-root children do not get the parent's attribute. v-bind()in<style>turns a reactive value into a CSS custom property.- Alternatives: CSS Modules (
<style module>), utility classes; scoping is not Shadow DOM.
Clarifying questions expected:
- "Is the third-party component's markup rendered by a Vue component (so
:deepworks) or injected HTML?"
Code / implementation expected: Optional. Reading the compiled selectors, or a small component showing :deep(), is a strong bonus.