Backtestsvuerun-20261005-155915#12124

Issue #12124 Merged fix PR #12125 Run 5 Oct 2026 · run-20261005-155915 vuejs/core

defineCustomElement can accidentally override members of the Element prototype

Worse

The merged fix was judged better than our patch.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Patch A is the safer fix: it resolves the accidental-override problem with a dev warning and changes no runtime behavior.

Correctness: The issue lists a warning as one acceptable outcome. Patch A adds a dev-only warning in `_resolveProps` whenever a declared prop key already exists on the element prototype. Runtime behavior stays the same, so the user is told about the conflict and nothing existing breaks.

Patch B goes further and stops defining element properties for any prop whose name exists on the prototype chain. That catches very common prop names such as `title`, `id`, `hidden`, `lang` and `dir`. Two regressions follow:
- Code that sets `el.title = someObject` from plain JS would silently hit the native setter. The value would be stringified and the Vue prop would never update.
- `_setupExpose` changes from `hasOwn` to `key in this`, so exposed members that shadow inherited ones (e.g. an exposed `focus`) are now dropped.

B patches `patchProp` to cover the Vue-parent rendering path, but the non-Vue JS property path, the main use of custom elements, loses functionality. Turning a dev-time naming mistake into silent runtime breakage for existing users is a significant risk.

Tests: Both patches add tests that would fail before their change. A covers attribute-driven, reflected-attribute (`id`), and Vue-rendered (`hasAttribute`) conflicts, and checks that the warning fires. B's tests are thorough for its own semantics, but they lock in the breaking behavior.

Scope and craft: A is minimal, follows existing warning conventions, and is easy to reason about. B touches three code paths (props, expose, `patchProp`). It adds a `@ts-expect-error` to reach a private field and widens the expose behavior change beyond the issue's ask, which adds risk.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

6m 40s

Wall-clock time in the container

Full test suite

No new failures

3,667 passed · 6 skipped · 3,673 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

130vs 79 merged

Changed lines, ours vs merged

Vue version

3.4.5

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-aob5zf?file=index.html

Steps to reproduce

I defined a Vue component with tagName as a property, and used that, together with defineCustomElement to define the hello-world webcomponent.

0 is obviously already defined in the Element prototype.

What is expected?

I expected to maybe be able to create _only_ the tag-name attribute (and no matching tagName property), or a warning that I'm accidentally overwriting important Element properties. Or a way to remap the tag-name attribute to a different property.

What is actually happening?

Vue's defineCustomElement happily overwrites the tagName property of the Element prototype without warning.

I know this is user error, but I was surprised that Vue let me.

System Info

_No response_

Any additional comments?

In Lit, you can be explicit about what property/attribute something maps to, that would be super cool here too:

@property({ attribute: 'tag-name' }) nonConfictingPropertyName;

We managed to put us in a situation where the attribute (which is not problematic) is causing issues because Vue generated an override for the tagName property (which is problematic), while we don't use that often.

The two patches

Our patch+129 −1
packages/runtime-dom/__tests__/customElement.spec.tsindex 27c7121c2..16c3e73f3 100644@@ -148,6 +148,72 @@ describe('defineCustomElement', () => {   })    describe('props', () => {+    test('should not override native element members', async () => {+      const E = defineCustomElement({+        props: {+          tagName: String,+          nodeName: String,+        },+        render() {+          return h('div', `${this.tagName} ${this.nodeName}`)+        },+      })+      customElements.define('my-el-native-prop', E)+      container.innerHTML = `<my-el-native-prop tag-name="foo" node-name="bar"></my-el-native-prop>`+      const e = container.childNodes[0] as VueElement+      // native members are preserved on the element and prototype+      expect(e.tagName).toBe('MY-EL-NATIVE-PROP')+      expect(e.nodeName).toBe('MY-EL-NATIVE-PROP')+      expect(Object.prototype.hasOwnProperty.call(e, 'tagName')).toBe(false)+      // the props can still be set via attributes+      expect(e.shadowRoot!.innerHTML).toBe('<div>foo bar</div>')+      e.setAttribute('tag-name', 'baz')+      await nextTick()+      expect(e.shadowRoot!.innerHTML).toBe('<div>baz bar</div>')+      expect(e.tagName).toBe('MY-EL-NATIVE-PROP')+      expect(+        `Prop "tagName" conflicts with an existing property on the custom element`,+      ).toHaveBeenWarned()+      expect(+        `Prop "nodeName" conflicts with an existing property on the custom element`,+      ).toHaveBeenWarned()+    })++    test('should pass props conflicting with native members from Vue parent', async () => {+      const E = defineCustomElement({+        props: {+          tagName: String,+          title: Object,+        },+        render() {+          return h('div', `${this.tagName} ${this.title && this.title.a}`)+        },+      })+      customElements.define('my-el-native-prop-parent', E)+      render(+        h('my-el-native-prop-parent', { 'tag-name': 'foo', title: { a: 1 } }),+        container,+      )+      const e = container.childNodes[0] as VueElement+      expect(e.tagName).toBe('MY-EL-NATIVE-PROP-PARENT')+      expect(e.shadowRoot!.innerHTML).toBe('<div>foo 1</div>')++      render(+        h('my-el-native-prop-parent', { tagName: 'bar', title: { a: 2 } }),+        container,+      )+      await nextTick()+      expect(e.tagName).toBe('MY-EL-NATIVE-PROP-PARENT')+      expect(e.shadowRoot!.innerHTML).toBe('<div>bar 2</div>')+      expect(`Failed setting prop`).not.toHaveBeenWarned()+      expect(+        `Prop "tagName" conflicts with an existing property on the custom element`,+      ).toHaveBeenWarned()+      expect(+        `Prop "title" conflicts with an existing property on the custom element`,+      ).toHaveBeenWarned()+    })+     const E = defineCustomElement({       props: {         foo: [String, null],@@ -2124,6 +2190,30 @@ describe('defineCustomElement', () => {         `[Vue warn]: Exposed property "value" already exists on custom element.`,       ).toHaveBeenWarned()     })++    test('should not override native members via expose', () => {+      const E = defineCustomElement({+        setup(_, { expose }) {+          expose({+            tagName: 'overridden',+            focus: 'overridden',+          })+          return () => h('div', 'hello')+        },+      })+      customElements.define('my-el-expose-native', E)++      container.innerHTML = `<my-el-expose-native></my-el-expose-native>`+      const e = container.childNodes[0] as VueElement+      expect(e.tagName).toBe('MY-EL-EXPOSE-NATIVE')+      expect(typeof e.focus).toBe('function')+      expect(+        `[Vue warn]: Exposed property "tagName" already exists on custom element.`,+      ).toHaveBeenWarned()+      expect(+        `[Vue warn]: Exposed property "focus" already exists on custom element.`,+      ).toHaveBeenWarned()+    })   })    test('async & nested custom elements', async () => {packages/runtime-dom/src/apiCustomElement.tsindex 9422f58d6..d187a4a53 100644@@ -454,7 +454,9 @@ export class VueElement     const exposed = this._instance && this._instance.exposed     if (!exposed) return     for (const key in exposed) {-      if (!hasOwn(this, key)) {+      // also check the prototype chain so that native element members+      // (e.g. `tagName`, `focus`) are not shadowed+      if (!(key in this)) {         // exposed properties are readonly         Object.defineProperty(this, key, {           // unwrap ref to be consistent with public instance behavior@@ -479,6 +481,19 @@ export class VueElement      // defining getter/setters on prototype     for (const key of declaredPropKeys.map(camelize)) {+      // do not shadow native members inherited from the element prototype+      // chain (e.g. `tagName`). Own properties set before upgrade are fine+      // to override. The prop can still be set via its attribute.+      if (!hasOwn(this, key) && key in this) {+        if (__DEV__) {+          warn(+            `Prop "${key}" conflicts with an existing property on the ` ++              `custom element and will not be defined as an element ` ++              `property. Use the "${hyphenate(key)}" attribute instead.`,+          )+        }+        continue+      }       Object.defineProperty(this, key, {         get(this: VueElement) {           return this._getProp(key)packages/runtime-dom/src/patchProp.tsindex 095a89403..13b98c3ef 100644@@ -5,6 +5,7 @@ import { patchDOMProp } from './modules/props' import { patchEvent } from './modules/events' import {   camelize,+  hasOwn,   isFunction,   isModelListener,   isOn,@@ -40,6 +41,19 @@ export const patchProp: DOMRendererOptions['patchProp'] = (     if (!isModelListener(key)) {       patchEvent(el, key, prevValue, nextValue, parentComponent)     }+  } else if (+    (el as VueElement)._isVueCE &&+    isNativeMemberPropForVueCE(el as VueElement, key)+  ) {+    // declared props that conflict with native element members (e.g. tagName)+    // are not defined as element properties, so set them on the CE directly+    ;(el as VueElement)._setProp(+      camelize(key),+      nextValue,+      true,+      // @ts-expect-error _patching is private+      !(el as VueElement)._patching,+    )   } else if (     key[0] === '.'       ? ((key = key.slice(1)), true)@@ -171,3 +185,12 @@ function shouldSetAsPropForVueCE(el: VueElement, key: string) {     ? props.some(prop => camelize(prop) === camelKey)     : Object.keys(props).some(prop => camelize(prop) === camelKey) }++function isNativeMemberPropForVueCE(el: VueElement, key: string) {+  const camelKey = camelize(key)+  return (+    !hasOwn(el, camelKey) &&+    camelKey in el &&+    shouldSetAsPropForVueCE(el, key)+  )+} 
Merged fix · PR #12125+78 −1
packages/runtime-dom/__tests__/customElement.spec.tsindex 27c7121c2..8763625bd 100644@@ -237,6 +237,7 @@ describe('defineCustomElement', () => {       await nextTick()       expect(e.shadowRoot!.innerHTML).toBe('<div>foo2</div><div>bar2</div>')       expect(e.getAttribute('foo')).toBe('foo2')+      expect(e.foo).toBe('foo2')       expect(e.hasAttribute('bar')).toBe(false)        // change prop then attr@@ -2489,6 +2490,76 @@ describe('defineCustomElement', () => {     expect(e.shadowRoot!.innerHTML).toBe(`false,boolean`)   }) +  test('prop name conflicts with native property', () => {+    const E = defineCustomElement({+      props: {+        tagName: {+          type: String,+        },+      },+      render() {+        return this.tagName+      },+    })+    customElements.define('el-attr-tag-name', E)+    container.innerHTML = '<el-attr-tag-name tag-name="foo">'+    const e = container.childNodes[0] as VueElement+    expect(e.shadowRoot!.innerHTML).toBe(`foo`)+    expect(e.tagName).toBe('foo')+    expect(+      `[Vue warn]: Custom element prop "tagName" conflicts with an existing property on the element and will overwrite it.`,+    ).toHaveBeenWarned()+  })++  test('prop name conflicts with reflected native property', async () => {+    const E = defineCustomElement({+      props: {+        id: String,+      },+      render() {+        return this.id+      },+    })+    customElements.define('el-attr-id', E)+    container.innerHTML = '<el-attr-id id="foo">'+    const e = container.childNodes[0] as VueElement++    e.setAttribute('id', 'bar')+    await nextTick()+    expect(e.shadowRoot!.innerHTML).toBe(`bar`)+    expect(e.id).toBe('bar')+    expect(+      `[Vue warn]: Custom element prop "id" conflicts with an existing property on the element and will overwrite it.`,+    ).toHaveBeenWarned()+  })++  test('native method conflict when rendered by Vue', () => {+    const value = { text: 'foo' }+    const E = defineCustomElement({+      props: {+        hasAttribute: Object,+      },+      render() {+        return this.hasAttribute!.text+      },+    })+    customElements.define('el-vue-has-attribute', E)++    render(+      h('el-vue-has-attribute', {+        'has-attribute': value,+      }),+      container,+    )++    const e = container.firstChild as VueElement+    expect(e.shadowRoot!.innerHTML).toBe('foo')+    expect((e as any).hasAttribute).toBe(value)+    expect(+      `[Vue warn]: Custom element prop "hasAttribute" conflicts with an existing property on the element and will overwrite it.`,+    ).toHaveBeenWarned()+  })+   test('hyphenated attr removal', async () => {     const E = defineCustomElement({       props: {packages/runtime-dom/src/apiCustomElement.tsindex 9422f58d6..ede68a516 100644@@ -477,8 +477,14 @@ export class VueElement       }     } -    // defining getter/setters on prototype+    // define getter/setters for declared props     for (const key of declaredPropKeys.map(camelize)) {+      if (__DEV__ && key in Object.getPrototypeOf(this)) {+        warn(+          `Custom element prop "${key}" conflicts with an existing property ` ++            `on the element and will overwrite it.`,+        )+      }       Object.defineProperty(this, key, {         get(this: VueElement) {           return this._getProp(key)