mirror of https://github.com/vuejs/core.git
fix(custom-element): properly resolve props for sync component defs (#12855)
close #12854
This commit is contained in:
parent
1d41d4de7f
commit
a683c80cf4
|
@ -444,6 +444,36 @@ describe('defineCustomElement', () => {
|
||||||
const e = container.childNodes[0] as VueElement
|
const e = container.childNodes[0] as VueElement
|
||||||
expect(e.shadowRoot!.innerHTML).toBe('hello')
|
expect(e.shadowRoot!.innerHTML).toBe('hello')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('prop types validation', async () => {
|
||||||
|
const E = defineCustomElement({
|
||||||
|
props: {
|
||||||
|
num: {
|
||||||
|
type: [Number, String],
|
||||||
|
},
|
||||||
|
bool: {
|
||||||
|
type: Boolean,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
return h('div', [
|
||||||
|
h('span', [`${this.num} is ${typeof this.num}`]),
|
||||||
|
h('span', [`${this.bool} is ${typeof this.bool}`]),
|
||||||
|
])
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
customElements.define('my-el-with-type-props', E)
|
||||||
|
render(h('my-el-with-type-props', { num: 1, bool: true }), container)
|
||||||
|
const e = container.childNodes[0] as VueElement
|
||||||
|
// @ts-expect-error
|
||||||
|
expect(e.num).toBe(1)
|
||||||
|
// @ts-expect-error
|
||||||
|
expect(e.bool).toBe(true)
|
||||||
|
expect(e.shadowRoot!.innerHTML).toBe(
|
||||||
|
'<div><span>1 is number</span><span>true is boolean</span></div>',
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('attrs', () => {
|
describe('attrs', () => {
|
||||||
|
|
|
@ -269,11 +269,6 @@ export class VueElement
|
||||||
this._root = this
|
this._root = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(this._def as ComponentOptions).__asyncLoader) {
|
|
||||||
// for sync component defs we can immediately resolve props
|
|
||||||
this._resolveProps(this._def)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback(): void {
|
connectedCallback(): void {
|
||||||
|
@ -391,12 +386,7 @@ export class VueElement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._numberProps = numberProps
|
this._numberProps = numberProps
|
||||||
|
this._resolveProps(def)
|
||||||
if (isAsync) {
|
|
||||||
// defining getter/setters on prototype
|
|
||||||
// for sync defs, this already happened in the constructor
|
|
||||||
this._resolveProps(def)
|
|
||||||
}
|
|
||||||
|
|
||||||
// apply CSS
|
// apply CSS
|
||||||
if (this.shadowRoot) {
|
if (this.shadowRoot) {
|
||||||
|
|
Loading…
Reference in New Issue