defineCustomElement
looses provide context configured by configureApp
on HMR
#12453
Labels
🔨 p3-minor-bug
Priority 3: this fixes a bug, but is an edge case that only affects very specific usage.
scope: custom elements
scope: hmr
Vue version
3.5.12
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-kennhm?file=src%2FApp.ce.vue
Steps to reproduce
App.ce.vue
after the app is runningIf you create a custom element with
defineCustomElement
and provide something in the app viaconfigureApp
the provided context gets lost when a HMR occurs.What is expected?
The provide context should be kept
What is actually happening?
The provide context will be lost
System Info
No response
Any additional comments?
This is happening because when the custom element will be mounted a VNode will be created that will be linked to the app via
_ceVNode
(seecore/packages/runtime-dom/src/apiCustomElement.ts
Line 423 in 06310e8
core/packages/runtime-dom/src/apiCustomElement.ts
Line 523 in 06310e8
A possible solution would be to link the newly created VNode with the app or to not create a new VNode on every HMR.
Here is a snippet of a custom definition of
defineCustomElement
which I did which worked for me:There you first create a VNode with the component and then create the app with the vnode. This way you can set the
ce
property on the VNode and don't have to create one on every HMRThe text was updated successfully, but these errors were encountered: