* is custom element?
*/
isCE?: boolean
+ /**
+ * custom element specific HMR method
+ */
+ ceReload?: () => void
// the rest are only for stateful components ---------------------------------
ClassComponent,
isClassComponent
} from './component'
-import { queueJob, queuePostFlushCb } from './scheduler'
+import { nextTick, queueJob } from './scheduler'
import { extend } from '@vue/shared'
import { warn } from './warning'
// on patch.
hmrDirtyComponents.add(component)
// 3. Make sure to unmark the component after the reload.
- queuePostFlushCb(() => {
+ nextTick(() => {
hmrDirtyComponents.delete(component)
})
}
// invalidate options resolution cache
instance.appContext.optionsCache.delete(instance.type as any)
- if (instance.parent) {
+ if (instance.ceReload) {
+ // custom element
+ instance.ceReload()
+ } else if (instance.parent) {
// 4. Force the parent instance to re-render. This will cause all updated
// components to be unmounted and re-mounted. Queue the update so that we
// don't end up forcing the same parent to re-render multiple times.
* @internal
*/
_instance: ComponentInternalInstance | null = null
- /**
- * @internal
- */
- _connected = false
+
+ private _connected = false
+ private _styles?: HTMLStyleElement[]
constructor(
private _def: ComponentOptions & { styles?: string[] },
instance.isCE = true
// HMR
if (__DEV__) {
- instance.appContext.reload = () => {
- render(this._createVNode(), this.shadowRoot!)
- this.shadowRoot!.querySelectorAll('style').forEach(s => {
- this.shadowRoot!.removeChild(s)
- })
+ instance.ceReload = () => {
+ this._instance = null
+ // reset styles
+ if (this._styles) {
+ this._styles.forEach(s => this.shadowRoot!.removeChild(s))
+ this._styles.length = 0
+ }
this._applyStyles()
+ // reload
+ render(this._createVNode(), this.shadowRoot!)
}
}
const s = document.createElement('style')
s.textContent = css
this.shadowRoot!.appendChild(s)
+ // record for HMR
+ if (__DEV__) {
+ ;(this._styles || (this._styles = [])).push(s)
+ }
})
}
}