Description
Vue version
3.5.13
Link to minimal reproduction
https://github.com/LoveVin/vue3-issue-demo
Steps to reproduce
I need to customize a web component. It has been working fine in previous Vue 2 projects, but I’m encountering issues when running it in a Vue 3 project.
After troubleshooting, I found that if I assign a value to this.name within the constructor of the custom element class, the name attribute is lost when the custom component is rendered on the page. The source code is <template> <aa-bb name="123"></aa-bb> </template>
, but in the browser, it renders as <aa-bb data-v-7a7a37b1></aa-bb>
, with the name attribute missing. This does not happen in Vue 2 projects.
The issue can be reproduced with the vue2-demo and vue3-demo created using Vite. You can find the compressed packages below. After downloading and installing them, the issue can be replicated.
I have also verified that the same issue occurs with Vue CLI. Using CDN to load Vue does not have this issue, nor does a native project. Therefore, I suspect it might be related to the Vue single-file component template packages.
Because this is a TypeScript project, when defining class properties, it’s necessary to initialize them within the constructor. As a result, the properties that are initialized later cannot be found.
What is expected?
<aa-bb name="123" data-v-7a7a37b1></aa-bb>
What is actually happening?
<aa-bb data-v-7a7a37b1></aa-bb>
System Info
System:
OS: macOS 13.5 arm64 Apple M1 Pro
Binaries:
Node: 20.18.0
npmPackages:
vue: ^3.5.13 => 3.5.13
Any additional comments?
Why is this happening? Is it a bug in some of the Vue 3 compilation packages? Can it be fixed?