Skip to content
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

Child component cannot render when there is same named data. #3270

Closed
ustbhuangyi opened this issue Feb 20, 2021 · 6 comments
Closed

Child component cannot render when there is same named data. #3270

ustbhuangyi opened this issue Feb 20, 2021 · 6 comments
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.

Comments

@ustbhuangyi
Copy link
Contributor

Version

3.0.5

Reproduction link

https://codesandbox.io/s/divine-fog-7wep8?file=/src/App.vue

Steps to reproduce

Open this page

What is expected?

HelloWorld component rendered.

What is actually happening?

HelloWorld component do not render..

@HcySunYang
Copy link
Member

This is because the helloWorld is analyzed as the binding of setup(SETUP_MAYBE_REF) when compileScript analyzes the bindings. It will generate the following code:

export function render(_ctx, _cache, $props, $setup, $data, $options) {
  return (_openBlock(), _createBlock(_Fragment, null, [
    _hoisted_1,
    _createTextVNode(" " + _toDisplayString($setup.helloWorld) + " ", 1 /* TEXT */),
    _createVNode($setup["helloWorld"], { msg: "Hello Vue 3 in CodeSandbox!" })
  ], 64 /* STABLE_FRAGMENT */))
}

Here, $setup["helloWorld"] is problematic.

@HcySunYang HcySunYang added 🐞 bug Something isn't working 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem labels Feb 20, 2021
@HcySunYang
Copy link
Member

Workaround: As long as the component name in the template is not the same as the binding, there will be ok.

@yingpengsha
Copy link

The source code clearly states that setup components take precedence over user components. Maybe it's not a bug, It's counterintuitive though. @HcySunYang
https://github.com/vuejs/vue-next/blob/58c46d77eac05ee72f17aa2669239c4d7c9a3abe/packages/compiler-core/src/transforms/transformElement.ts#L260

@HcySunYang
Copy link
Member

This is not about component priority, it is about components/directives and data name conflicts

@yingpengsha
Copy link

Maybe it should be resolved in resolveComponent.

@ovidiuc
Copy link

ovidiuc commented Mar 9, 2021

Not sure if this is related, but if you have a child component named ChildComponent and setup data named childComponent (so not the same name, but the first letter lowercased) the child also doesn't render. I'm leaving here the console warnings I get, so people can find this bug when searching for a solution:

[Vue warn]: Avoid app logic that relies on enumerating keys on a component instance. The keys will be empty in production mode to avoid performance overhead. 

or sometimes:

[Vue warn]: Invalid vnode type when creating vnode: null.

https://codesandbox.io/s/wonderful-meadow-p8nb6?file=/src/components/ParentComponent.vue

I would say this is not necessary a minor bug, as the label suggests. I've ran into the situation twice already in a short period of time, trying to upgrade an existing vue 2 codebase. And with different console warnings, so had to investigate both times, a lot of time wasted. Imagine a production site having important parts of the page gone missing with no clue as to what is going on.

@HcySunYang HcySunYang added the need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further. label Mar 29, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Oct 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. has workaround A workaround has been found to avoid the problem 🐞 bug Something isn't working need guidance The approach/solution in the PR is unclear and requires guidance from maintainer to proceed further.
Projects
None yet
Development

No branches or pull requests

4 participants