Backtestsvuerun-20261009-161443#12124

Issue #12124 Merged fix PR #12125 Run 9 Oct 2026 · run-20261009-161443 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.

The issue's main complaint is that Vue silently overrides native Element members like `tagName`. It explicitly accepts a warning as a remedy. Patch A adds a dev-only warning when a declared prop name already exists on the element's prototype. The prop/property behavior stays exactly as before, so existing code keeps working. Its tests cover the reported `tagName` case, a reflected native property (`id`), and a native method (`hasAttribute`) set from a Vue render. Each asserts the warning, and those assertions would fail without the change.

Patch B goes further. It stops defining accessors for any prop that collides with something in the prototype chain, routes Vue-rendered bindings for those props through a new patchProp branch, and also changes `_applyExpose` to skip anything in the prototype chain. That stops the override, but it is a silent breaking change for common prop names like `title`, `hidden`, `lang`, `dir` and `id`. JS code doing `el.title = someObject` used to set the Vue prop. Now it hits the native setter, which stringifies the value and only reaches the prop indirectly through attribute reflection. For non-reflected native members it doesn't reach the prop at all. The expose change similarly alters existing behavior for names like `focus`. The extra patchProp branch adds complexity and runs before the existing `.`/`^`/shouldSetAsProp logic, which adds risk on a hot path. B's tests are thorough, but they lock in this riskier semantic change.

Patch A satisfies the issue's ask with minimal risk. Patch B's broader redesign introduces regressions for existing users, so A is the better fix.

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

Wall-clock time in the container

Full test suite

No new failures

701 passed · 1 skipped · 702 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

149vs 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+148 −1
packages/runtime-dom/__tests__/customElement.spec.tsindex 27c7121c2..8bea6b6aa 100644@@ -148,6 +148,89 @@ describe('defineCustomElement', () => {   })    describe('props', () => {+    test('should not override native element members with props', async () => {+      const E = defineCustomElement({+        props: {+          tagName: String,+          title: String,+          msg: String,+        },+        render() {+          return h('div', `${this.tagName}|${this.title}|${this.msg}`)+        },+      })+      customElements.define('my-el-native-props', E)++      container.innerHTML = `<my-el-native-props tag-name="foo" title="bar" msg="baz"></my-el-native-props>`+      const e = container.childNodes[0] as VueElement & { msg: string }++      // native members are preserved+      expect(e.tagName).toBe('MY-EL-NATIVE-PROPS')+      expect(Object.getOwnPropertyDescriptor(e, 'tagName')).toBeUndefined()+      expect(Object.getOwnPropertyDescriptor(e, 'title')).toBeUndefined()+      expect(e.title).toBe('bar')+      // non-conflicting props still get element properties+      expect(e.msg).toBe('baz')+      // conflicting props are still settable via attributes+      expect(e.shadowRoot!.innerHTML).toBe(`<div>foo|bar|baz</div>`)++      e.setAttribute('tag-name', 'qux')+      // native setter reflects to the attribute, which updates the prop+      e.title = 'quux'+      await nextTick()+      expect(e.tagName).toBe('MY-EL-NATIVE-PROPS')+      expect(e.shadowRoot!.innerHTML).toBe(`<div>qux|quux|baz</div>`)++      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()+      expect(`Prop "msg" conflicts`).not.toHaveBeenWarned()+    })++    test('should pass props conflicting with native members from Vue templates', async () => {+      const E = defineCustomElement({+        props: {+          tagName: String,+          title: Object,+        },+        render() {+          return h('div', `${this.tagName}|${JSON.stringify(this.title)}`)+        },+      })+      customElements.define('my-el-native-props-vnode', E)++      const tagName = ref('foo')+      const title = ref<object>({ a: 1 })+      render(+        h(() =>+          h('my-el-native-props-vnode', {+            'tag-name': tagName.value,+            title: title.value,+          }),+        ),+        container,+      )+      const e = container.childNodes[0] as VueElement+      expect(e.tagName).toBe('MY-EL-NATIVE-PROPS-VNODE')+      expect(e.shadowRoot!.innerHTML).toBe(`<div>foo|{"a":1}</div>`)++      tagName.value = 'bar'+      title.value = { b: 2 }+      await nextTick()+      expect(e.tagName).toBe('MY-EL-NATIVE-PROPS-VNODE')+      expect(e.shadowRoot!.innerHTML).toBe(`<div>bar|{"b":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 +2207,32 @@ describe('defineCustomElement', () => {         `[Vue warn]: Exposed property "value" already exists on custom element.`,       ).toHaveBeenWarned()     })++    test('should not override native element members when exposing', () => {+      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 & {+        focus: () => unknown+      }+      expect(e.tagName).toBe('MY-EL-EXPOSE-NATIVE')+      expect(e.focus).toBe(HTMLElement.prototype.focus)+      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..349c6ab6a 100644@@ -454,7 +454,8 @@ 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 to avoid shadowing native members+      if (!(key in this)) {         // exposed properties are readonly         Object.defineProperty(this, key, {           // unwrap ref to be consistent with public instance behavior@@ -479,6 +480,18 @@ export class VueElement      // defining getter/setters on prototype     for (const key of declaredPropKeys.map(camelize)) {+      // avoid shadowing native members of the element (e.g. `tagName`);+      // such props can still be set via their 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 exposed as an element property. ` ++              `Use the "${hyphenate(key)}" attribute to set it instead.`,+          )+        }+        continue+      }       Object.defineProperty(this, key, {         get(this: VueElement) {           return this._getProp(key)packages/runtime-dom/src/patchProp.tsindex 095a89403..170fbde45 100644@@ -5,6 +5,7 @@ import { patchDOMProp } from './modules/props' import { patchEvent } from './modules/events' import {   camelize,+  hasOwn,   isFunction,   isModelListener,   isOn,@@ -40,6 +41,21 @@ export const patchProp: DOMRendererOptions['patchProp'] = (     if (!isModelListener(key)) {       patchEvent(el, key, prevValue, nextValue, parentComponent)     }+  } else if (+    (el as VueElement)._isVueCE &&+    key[0] !== '.' &&+    key[0] !== '^' &&+    isNativeMemberPropForVueCE(el as VueElement, key)+  ) {+    // declared props that conflict with native element members (e.g. `tagName`)+    // have no accessor on the element, so set them on the component 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 +187,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)