Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Vue 3 debugging reference for reactivity issues, computed errors, watcher bugs, async failures, and SSR hydration problems.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
reference/local-components-not-in-descendants.md
1---2title: Locally Registered Components Are Not Available in Descendants3impact: HIGH4impactDescription: Common source of "component not found" errors in nested components5type: gotcha6tags: [vue3, component-registration, local-registration, scope, nested-components]7---89# Locally Registered Components Are Not Available in Descendants1011**Impact: HIGH** - Locally registered components are only available in the component where they are registered, NOT in its child or descendant components. This is a common source of "Unknown component" or "Failed to resolve component" errors when developers expect a component registered in a parent to be available in children.1213## Task Checklist1415- [ ] Import and register components in every file where they are used16- [ ] Do not expect parent's local components to be available in children17- [ ] If a component is needed in many places, consider global registration only as a last resort18- [ ] Use IDE auto-import features to simplify repeated imports1920**Incorrect:**21```vue22<!-- ParentComponent.vue -->23<script setup>24import Card from './Card.vue'25import ChildComponent from './ChildComponent.vue'26</script>2728<template>29<Card>Parent content</Card>30<ChildComponent />31</template>32```3334```vue35<!-- ChildComponent.vue -->36<script setup>37// WRONG: Expecting Card to be available because parent imported it38// This will cause "Failed to resolve component: Card" error39</script>4041<template>42<!-- ERROR: Card is not available here! -->43<Card>44Child content45</Card>46</template>47```4849**Correct:**50```vue51<!-- ParentComponent.vue -->52<script setup>53import Card from './Card.vue'54import ChildComponent from './ChildComponent.vue'55</script>5657<template>58<Card>Parent content</Card>59<ChildComponent />60</template>61```6263```vue64<!-- ChildComponent.vue -->65<script setup>66// CORRECT: Each component must import what it uses67import Card from './Card.vue'68</script>6970<template>71<Card>72Child content73</Card>74</template>75```7677## Common Scenarios7879### Scenario 1: Deeply Nested Components80```vue81<!-- GrandchildComponent.vue -->82<script setup>83// Even if parent and grandparent both use Card,84// grandchild must import it separately85import Card from '@/components/Card.vue'86import Button from '@/components/Button.vue'87</script>8889<template>90<Card>91<Button>Click me</Button>92</Card>93</template>94```9596### Scenario 2: Slot Content with Components97```vue98<!-- Parent.vue -->99<script setup>100import Modal from './Modal.vue'101import Form from './Form.vue'102</script>103104<template>105<!-- Form is registered in Parent, so it works in slot content -->106<Modal>107<Form /> <!-- This works because slot content is compiled in Parent's scope -->108</Modal>109</template>110```111112```vue113<!-- Modal.vue -->114<script setup>115// Modal doesn't need to import Form because slot content116// is compiled in the parent's scope, not Modal's scope117</script>118119<template>120<div class="modal">121<slot /> <!-- Form component works here because it's parent's slot content -->122</div>123</template>124```125126### Scenario 3: Dynamic Components127```vue128<!-- Container.vue -->129<script setup>130import TabA from './TabA.vue'131import TabB from './TabB.vue'132import { ref, shallowRef } from 'vue'133134// When using dynamic components, all possible components must be imported135const currentTab = shallowRef(TabA)136</script>137138<template>139<component :is="currentTab" />140</template>141```142143## Why This Design?144145Local registration provides:1461. **Explicit dependencies** - You can see exactly what each component uses1472. **Tree-shaking** - Unused components are removed from bundles1483. **Clear scope** - No magic or implicit behavior149150## Reference151- [Vue.js Component Registration - Local Registration](https://vuejs.org/guide/components/registration.html#local-registration)152