]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(custom-element): prevent defineCustomElement from mutating the options object...
authorFolee <597171538@qq.com>
Tue, 2 Sep 2025 08:56:33 +0000 (16:56 +0800)
committerGitHub <noreply@github.com>
Tue, 2 Sep 2025 08:56:33 +0000 (16:56 +0800)
packages/runtime-dom/__tests__/customElement.spec.ts
packages/runtime-dom/src/apiCustomElement.ts

index 07ea091486e5909dde5afeb57a79449f8cd9ad59..cb09cf4d9e7d487c869a12861e2bea2a5949af5d 100644 (file)
@@ -1774,4 +1774,16 @@ describe('defineCustomElement', () => {
       `<el-hyphenated-attr-removal></el-hyphenated-attr-removal>`,
     )
   })
+
+  test('no unexpected mutation of the 1st argument', () => {
+    const Foo = {
+      name: 'Foo',
+    }
+
+    defineCustomElement(Foo, { shadowRoot: false })
+
+    expect(Foo).toEqual({
+      name: 'Foo',
+    })
+  })
 })
index edf7c4313534d02d2ec09de6ffbd7cb35ddf72f9..0a1aa314ec6f7aaccaf46b77b4f9ac20d125a9c2 100644 (file)
@@ -172,8 +172,8 @@ export function defineCustomElement(
    */
   _createApp?: CreateAppFunction<Element>,
 ): 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<string, any>) {