diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 6f30053cfc2..d2cd3ad1ee3 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -363,6 +363,12 @@ export interface ComponentInternalInstance { */ ceReload?: (newStyles?: string[]) => void + /** + * custom element set prop + * @internal + */ + ceSetProp?: (prop: string, value: any) => void + // the rest are only for stateful components --------------------------------- // main proxy that serves as the public instance (`this`) diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 5a4292b6f36..4a82608b6ca 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -480,6 +480,10 @@ function resolvePropValue( } else { value = defaultValue } + + if (instance.isCE) { + instance.ceSetProp!(key, value) + } } // boolean casting if (opt[BooleanFlags.shouldCast]) { diff --git a/packages/runtime-dom/__tests__/customElement.spec.ts b/packages/runtime-dom/__tests__/customElement.spec.ts index fb746f72c4a..de593d7707c 100644 --- a/packages/runtime-dom/__tests__/customElement.spec.ts +++ b/packages/runtime-dom/__tests__/customElement.spec.ts @@ -39,6 +39,7 @@ describe('defineCustomElement', () => { expect(e).toBeInstanceOf(E) expect(e._instance).toBeTruthy() expect(e.shadowRoot!.innerHTML).toBe(`
hello
`) + expect(e.getAttribute('msg')).toBe(`hello`) }) test('should work w/ manual instantiation', () => { diff --git a/packages/runtime-dom/src/apiCustomElement.ts b/packages/runtime-dom/src/apiCustomElement.ts index 01ce2bad464..b99991ea272 100644 --- a/packages/runtime-dom/src/apiCustomElement.ts +++ b/packages/runtime-dom/src/apiCustomElement.ts @@ -409,6 +409,10 @@ export class VueElement extends BaseClass { break } } + + instance.ceSetProp = (key: string, value: any) => { + this._setProp(key, value, true, false) + } } } return vnode