-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we use a builtin tag to recurse self-reference component ? #2827
Comments
I would say in practice, naming a component the same in different folders is a bad practice (https://v3.vuejs.org/style-guide/#tightly-coupled-component-names-strongly-recommended and all the naming recommendations). In Vue 2, we used to need a <template>
<h1>OUTER COMPONENT</h1>
<Foo />
</template>
<script>
import Foo from '../inner/Foo.vue'
export default {
name: 'OuterFoo',
components: { Foo },
}
</script>
|
At the very least a console warning would be nice. This would be a very difficult bug to fix in a larger app. |
ping @HcySunYang @posva @yyx990803 |
While it might be a bad practice to name multiple components with the same name, it can indeed be difficult to fix such issues with big codebases (took us some time to find this issue). |
Even with moderately sized code-base this suddenly popped up in a few places for us after trying vue/next. Webpack hot-reload took the initial blame, as it seemed the file itself was not being properly loaded (parent component being loaded in place of the child component with the same file-name). For us, the use case was the self-contained components displayed as separate pages. For example, there is Privacy Policy dialog box under "components", and then there is Privacy Policy page, under "pages". Both file names make sense as just |
@luwuer Can you draft an RFC? If you don't have time, I can do this instead |
Since the inferred filename is actually causing breakage, I adjusted its priority in abd129d and it is now used as a fallback only when normal resolution fails. The issue with adding another built-in tag is that it could technically be a breaking change. I think with the fix in abd129d, it is no longer strictly necessary. If we do want something like that, |
What problem does this feature solve?
Now vue using filename to assert if need to recursive components themselves.
selfname
is inferred from filenamehttps://github.com/vuejs/vue-next/blob/64d4681e4b9d88e17cd1515014866d43d0424d14/packages/compiler-core/src/transforms/transformElement.ts#L266-L273
This way may has these pitfalls:
If we use a builtin tag:
What does the proposed API look like?
Use a builtin tag instead of filename assertion, tag name maybe:
self
_self
@yyx990803 @posva @edison1105
The text was updated successfully, but these errors were encountered: