/**
* @internal
*/
- _root!: Element | ShadowRoot
+ _root: Element | ShadowRoot
/**
* @internal
*/
*/
_teleportTargets?: Set<Element>
- protected _def: Def
- protected _props: Record<string, any>
- protected _createApp: CreateAppFunction<E, C>
protected _connected = false
protected _resolved = false
protected _numberProps: Record<string, true> | null = null
protected _pendingResolve: Promise<void> | undefined
protected _parent: VueElementBase | undefined
+ protected _def: Def
+ protected _props: Record<string, any>
+ protected _createApp: CreateAppFunction<E, C>
+
/**
* dev only
*/
protected _ob?: MutationObserver | null = null
protected _slots?: Record<string, Node[]>
- protected abstract _hasPreRendered(): boolean | undefined
+ /**
+ * Check if this custom element needs hydration.
+ * Returns true if it has a pre-rendered declarative shadow root that
+ * needs to be hydrated.
+ */
+ protected abstract _needsHydration(): boolean
protected abstract _mount(def: Def): void
protected abstract _update(): void
protected abstract _unmount(): void
this._createApp = createAppFn
this._nonce = def.nonce
- if (this._hasPreRendered()) {
+ if (this._needsHydration()) {
+ this._root = this.shadowRoot!
+ } else {
if (def.shadowRoot !== false) {
this.attachShadow(
extend({}, def.shadowRootOptions, {
private _mountComponent(def: Def): void {
this._mount(def)
+ // apply expose after mount
this._processExposed()
}
if (!exposed) return
for (const key in exposed) {
if (!hasOwn(this, key)) {
+ // exposed properties are readonly
Object.defineProperty(this, key, {
+ // unwrap ref to be consistent with public instance behavior
get: () => unref(exposed[key]),
})
} else if (__DEV__) {
super(def, props, createAppFn)
}
- protected _hasPreRendered(): boolean | undefined {
+ protected _needsHydration(): boolean {
if (this.shadowRoot && this._createApp !== createApp) {
- this._root = this.shadowRoot
+ return true
} else {
if (__DEV__ && this.shadowRoot) {
warn(
`defined as hydratable. Use \`defineSSRCustomElement\`.`,
)
}
- return true
}
+ return false
}
protected _mount(def: InnerComponentDef): void {
super(def, props, createAppFn)
}
- protected _hasPreRendered(): boolean | undefined {
+ protected _needsHydration(): boolean {
if (this.shadowRoot && this._createApp !== createVaporApp) {
- this._root = this.shadowRoot
+ return true
} else {
if (__DEV__ && this.shadowRoot) {
warn(
`defined as hydratable. Use \`defineVaporSSRCustomElement\`.`,
)
}
- return true
}
+ return false
}
protected _mount(def: VaporInnerComponentDef): void {
if ((__DEV__ || __FEATURE_PROD_DEVTOOLS__) && !def.name) {
this._def.configureApp(this._app)
}
- // For SSR custom elements, we need to create component in hydration context
- if (this._createApp === createVaporSSRApp) {
+ // create component in hydration context
+ if (this.shadowRoot && this._createApp === createVaporSSRApp) {
withHydration(this._root, this._createComponent.bind(this))
} else {
this._createComponent()