From 436866d449164c3c6113d2ae3314969dd25d0518 Mon Sep 17 00:00:00 2001
From: Folee <597171538@qq.com>
Date: Fri, 22 Aug 2025 04:34:33 +0800
Subject: [PATCH 1/2] fix(custom-element): the 2nd argument can unexpectedly
mutate the 1st argument of defineCustomElement
---
packages/runtime-dom/__tests__/customElement.spec.ts | 12 ++++++++++++
packages/runtime-dom/src/apiCustomElement.ts | 1 +
2 files changed, 13 insertions(+)
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..6814b8ffd77 100644
--- a/packages/runtime-dom/src/apiCustomElement.ts
+++ b/packages/runtime-dom/src/apiCustomElement.ts
@@ -172,6 +172,7 @@ export function defineCustomElement(
*/
_createApp?: CreateAppFunction,
): VueElementConstructor {
+ if (isPlainObject(options)) options = extend({}, options)
const Comp = defineComponent(options, extraOptions) as any
if (isPlainObject(Comp)) extend(Comp, extraOptions)
class VueCustomElement extends VueElement {
From 1be15affd6697a88d2423416d3cde3aaa5117a1b Mon Sep 17 00:00:00 2001
From: daiwei
Date: Tue, 2 Sep 2025 14:16:49 +0800
Subject: [PATCH 2/2] chore: tweaks
---
packages/runtime-dom/src/apiCustomElement.ts | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/packages/runtime-dom/src/apiCustomElement.ts b/packages/runtime-dom/src/apiCustomElement.ts
index 6814b8ffd77..0a1aa314ec6 100644
--- a/packages/runtime-dom/src/apiCustomElement.ts
+++ b/packages/runtime-dom/src/apiCustomElement.ts
@@ -172,9 +172,8 @@ export function defineCustomElement(
*/
_createApp?: CreateAppFunction,
): VueElementConstructor {
- if (isPlainObject(options)) options = extend({}, options)
- 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) {