@@ -201,6 +201,8 @@ const BaseClass = (
201201type InnerComponentDef = ConcreteComponent & CustomElementOptions
202202
203203export abstract class VueElementBase <
204+ E = Element ,
205+ C = Component ,
204206 Def extends CustomElementOptions & { props ?: any } = InnerComponentDef ,
205207 >
206208 extends BaseClass
@@ -218,7 +220,7 @@ export abstract class VueElementBase<
218220 /**
219221 * @internal
220222 */
221- _root : Element | ShadowRoot
223+ _root ! : Element | ShadowRoot
222224 /**
223225 * @internal
224226 */
@@ -230,7 +232,7 @@ export abstract class VueElementBase<
230232
231233 protected _def : Def
232234 protected _props : Record < string , any >
233- protected _createApp : CreateAppFunction < Element >
235+ protected _createApp : CreateAppFunction < E , C >
234236 protected _connected = false
235237 protected _resolved = false
236238 protected _numberProps : Record < string , true > | null = null
@@ -249,29 +251,27 @@ export abstract class VueElementBase<
249251 protected _ob ?: MutationObserver | null = null
250252 protected _slots ?: Record < string , Node [ ] >
251253
254+ protected abstract _hasPreRendered ( ) : boolean | undefined
255+ protected abstract _mountComponent ( def : Def ) : void
256+ protected abstract _updateComponent ( ) : void
257+ protected abstract _unmountComponent ( ) : void
258+
252259 constructor (
253260 /**
254261 * Component def - note this may be an AsyncWrapper, and this._def will
255262 * be overwritten by the inner component when resolved.
256263 */
257264 def : Def ,
258- props : Record < string , any > = { } ,
259- createAppFn : CreateAppFunction < Element > = createApp ,
265+ props : Record < string , any > | undefined = { } ,
266+ createAppFn : CreateAppFunction < E , C > ,
260267 ) {
261268 super ( )
262269 this . _def = def
263270 this . _props = props
264271 this . _createApp = createAppFn
265272 this . _nonce = def . nonce
266- if ( this . shadowRoot && createAppFn !== createApp ) {
267- this . _root = this . shadowRoot
268- } else {
269- if ( __DEV__ && this . shadowRoot ) {
270- warn (
271- `Custom element has pre-rendered declarative shadow root but is not ` +
272- `defined as hydratable. Use \`defineSSRCustomElement\`.` ,
273- )
274- }
273+
274+ if ( this . _hasPreRendered ( ) ) {
275275 if ( def . shadowRoot !== false ) {
276276 this . attachShadow (
277277 extend ( { } , def . shadowRootOptions , {
@@ -322,10 +322,6 @@ export abstract class VueElementBase<
322322 }
323323 }
324324
325- protected abstract _mountComponent ( def : Def ) : void
326- protected abstract _updateComponent ( ) : void
327- protected abstract _unmountComponent ( ) : void
328-
329325 protected _setParent (
330326 parent : VueElementBase | undefined = this . _parent ,
331327 ) : void {
@@ -643,7 +639,33 @@ export abstract class VueElementBase<
643639 }
644640}
645641
646- export class VueElement extends VueElementBase < InnerComponentDef > {
642+ export class VueElement extends VueElementBase <
643+ Element ,
644+ Component ,
645+ InnerComponentDef
646+ > {
647+ constructor (
648+ def : InnerComponentDef ,
649+ props : Record < string , any > | undefined = { } ,
650+ createAppFn : CreateAppFunction < Element , Component > = createApp ,
651+ ) {
652+ super ( def , props , createAppFn )
653+ }
654+
655+ protected _hasPreRendered ( ) : boolean | undefined {
656+ if ( this . shadowRoot && this . _createApp !== createApp ) {
657+ this . _root = this . shadowRoot
658+ } else {
659+ if ( __DEV__ && this . shadowRoot ) {
660+ warn (
661+ `Custom element has pre-rendered declarative shadow root but is not ` +
662+ `defined as hydratable. Use \`defineSSRCustomElement\`.` ,
663+ )
664+ }
665+ return true
666+ }
667+ }
668+
647669 protected _mountComponent ( def : InnerComponentDef ) : void {
648670 if ( ( __DEV__ || __FEATURE_PROD_DEVTOOLS__ ) && ! def . name ) {
649671 // @ts -expect-error
0 commit comments