From e322436887549c129e61eb58a0084167103451bb Mon Sep 17 00:00:00 2001 From: Folee <597171538@qq.com> Date: Tue, 2 Sep 2025 16:56:33 +0800 Subject: [PATCH] fix(custom-element): prevent defineCustomElement from mutating the options object (#13791) --- packages/runtime-dom/__tests__/customElement.spec.ts | 12 ++++++++++++ packages/runtime-dom/src/apiCustomElement.ts | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/runtime-dom/__tests__/customElement.spec.ts b/packages/runtime-dom/__tests__/customElement.spec.ts index 07ea09148..cb09cf4d9 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 edf7c4313..0a1aa314e 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) { -- 2.47.3