fix(custom-element): fix custom element props access on initial render

ref: #4792
This commit is contained in:
Evan You
2021-11-02 13:20:31 +08:00
parent 6916d725a0
commit 4b7f76e36a
2 changed files with 34 additions and 13 deletions

View File

@@ -180,7 +180,6 @@ export class VueElement extends BaseClass {
this._connected = true
if (!this._instance) {
this._resolveDef()
this._update()
}
}
@@ -231,17 +230,15 @@ export class VueElement extends BaseClass {
}
}
}
if (numberProps) {
this._numberProps = numberProps
this._update()
}
this._numberProps = numberProps
// check if there are props set pre-upgrade or connect
for (const key of Object.keys(this)) {
if (key[0] !== '_') {
this._setProp(key, this[key as keyof this])
this._setProp(key, this[key as keyof this], true, false)
}
}
// defining getter/setters on prototype
for (const key of rawKeys.map(camelize)) {
Object.defineProperty(this, key, {
@@ -253,7 +250,12 @@ export class VueElement extends BaseClass {
}
})
}
// apply CSS
this._applyStyles(styles)
// initial render
this._update()
}
const asyncDef = (this._def as ComponentOptions).__asyncLoader
@@ -282,10 +284,15 @@ export class VueElement extends BaseClass {
/**
* @internal
*/
protected _setProp(key: string, val: any, shouldReflect = true) {
protected _setProp(
key: string,
val: any,
shouldReflect = true,
shouldUpdate = true
) {
if (val !== this._props[key]) {
this._props[key] = val
if (this._instance) {
if (shouldUpdate && this._instance) {
this._update()
}
// reflect