diff --git a/packages/runtime-dom/__tests__/customElement.spec.ts b/packages/runtime-dom/__tests__/customElement.spec.ts index 07ea091486e..cb09cf4d9e7 100644 --- a/packages/runtime-dom/__tests__/customElement.spec.ts +++ b/packages/runtime-dom/__tests__/customElement.spec.ts @@ -1774,4 +1774,16 @@ describe('defineCustomElement', () => { ``, ) }) + + test('no unexpected mutation of the 1st argument', () => { + const Foo = { + name: 'Foo', + } + + defineCustomElement(Foo, { shadowRoot: false }) + + expect(Foo).toEqual({ + name: 'Foo', + }) + }) }) diff --git a/packages/runtime-dom/src/apiCustomElement.ts b/packages/runtime-dom/src/apiCustomElement.ts index edf7c431353..0a1aa314ec6 100644 --- a/packages/runtime-dom/src/apiCustomElement.ts +++ b/packages/runtime-dom/src/apiCustomElement.ts @@ -172,8 +172,8 @@ export function defineCustomElement( */ _createApp?: CreateAppFunction, ): VueElementConstructor { - const Comp = defineComponent(options, extraOptions) as any - if (isPlainObject(Comp)) extend(Comp, extraOptions) + let Comp = defineComponent(options, extraOptions) as any + if (isPlainObject(Comp)) Comp = extend({}, Comp, extraOptions) class VueCustomElement extends VueElement { static def = Comp constructor(initialProps?: Record) {