-
-
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
Custom element wrapped in HTMLElement duplicates component when using v-model #9885
Comments
Looking into this some more, it seems like the issue is coming from the fact that the custom element here uses a The other workaround I have right now is to remove the extra node when the component mounts. |
Working on getting a pull request up to fix this, and interestingly if put a small timeout around the initial setting of the value in
|
Seems to be some sort of collision with the update process in |
Ok, so I think I've settled on a better solution than making a change in the mentioned pull request. I think this can be handled on a case-by-case basis by library authors. The solution, I came up with was to wait for import { defineCustomElement, nextTick } from "vue";
import MyTextInput from "./Input.ce.vue";
export const TextInput = defineCustomElement(MyTextInput);
export default (function () {
if (customElements.get("my-input") === undefined) {
nextTick(() => {
customElements.define("my-input", TextInput);
});
}
})(); There is probably something clever you could do here with checking to see if your custom element is rendering in a Vue app (rather than Angular or React, for example), as well. |
Actually, after some additional investigation, this doesn't seem to work when multiple instances of a component are used in a specific view. I'll reopen the #11335 with some fixes to get the tests passing. |
Vue version
3.3.11
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-jeblju?file=src%2FApp.vue
Steps to reproduce
my-input
is double rendering when wrapped in adiv
while usingv-model
What is expected?
my-input
should be able to usev-model
when it is placed inside of anHTMLElement
.What is actually happening?
my-input
usesv-model
the contents of the custom element's shadow root are duplicated. This only happens when it is wrapped in anHTMLElement
like adiv
.my-input
's parent istemplate
this issue doesn't occur.defineCustomElement
, that are then reused in Vue (components created with Lit for example, don't seem impacted).System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.18.0 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 9.4.2 - /usr/local/bin/npm pnpm: 8.10.5 - /usr/local/bin/pnpm npmPackages: vue: ^3.3.11 => 3.3.13
Any additional comments?
I found this issue when working to get different
v-model
types working with custom elements, #9883.The text was updated successfully, but these errors were encountered: