Backtestsvuerun-20261013-093701#12124

Issue #12124 Merged fix PR #12125 Run 13 Oct 2026 · run-20261013-093701 vuejs/core

defineCustomElement can accidentally override members of the Element prototype

Better

Our patch was judged better than the merged fix.

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

The issue is that defineCustomElement silently defines an own `tagName` property that shadows the native `Element.prototype.tagName`. The reporter would accept either outcome: only the attribute is created with no matching property, or Vue warns about the clobbering.

Patch A fixes the root cause:
- It skips `Object.defineProperty` for declared props that already exist on the element's prototype chain, so native members like `tagName` and `click` keep working.
- It emits a dev warning explaining that the prop can still be passed via its attribute or via Vue vnode props.
- It deletes any pre-upgrade own property so the native member is not shadowed.
- Because those props no longer have an element property, it adds a `patchProp` branch (`isNativeMemberPropForVueCE` → `_setDeclaredProp`). This keeps Vue templates and render functions passing camelCase, hyphenated and `.`-prefixed props correctly, instead of falling back to native property sets or attribute stringification.
- It also tightens the expose path (`key in this` instead of `hasOwn`) so `expose()` cannot shadow native members either.
- Its tests are behavioral and would fail before the change. They check that `e.tagName` keeps its native value, `click` stays a function, no own property is created, attribute and vnode updates still reach the component (including after reactive changes), and pre-upgrade properties are dropped.

Patch B only adds a dev-mode warning and still overrides the native member. Its own test asserts `e.tagName` is 'foo', which codifies the breakage the issue complains about. That technically meets the minimal "or a warning" fallback, but the hazard remains: anything that reads `tagName` (or calls a shadowed method like `hasAttribute`) still breaks at runtime. Its tests mainly check that the warning fires, plus one unrelated assertion added to an existing test.

Patch A carries some behavior-change risk. Props named after native members such as `title` or `id` no longer get Vue-managed element properties, so imperative non-string assignment changes semantics. However, reflected attributes still flow through to the prop, and Vue-rendered usage is explicitly preserved. On balance, A resolves the reported problem at its source with careful edge handling and stronger tests. B only surfaces it.

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

7m 45s

Wall-clock time in the container

Full test suite

No new failures

703 passed · 1 skipped · 704 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

165vs 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+162 −3
packages/runtime-dom/__tests__/customElement.spec.tsindex 27c7121c2..0dba7c9c3 100644@@ -683,6 +683,98 @@ describe('defineCustomElement', () => {       expect(prop1Calls).toBe(2)       expect(prop2Calls).toBe(1)     })++    describe('props conflicting with native element members', () => {+      const ENative = defineCustomElement({+        props: {+          tagName: String,+          click: String,+        },+        render() {+          return h('div', null, `${this.tagName}|${this.click}`)+        },+      })+      customElements.define('my-el-native-props', ENative)++      test('should not override native members', async () => {+        container.innerHTML = `<my-el-native-props tag-name="foo" click="bar"></my-el-native-props>`+        const e = container.childNodes[0] as VueElement+        expect(e.tagName).toBe('MY-EL-NATIVE-PROPS')+        expect(typeof e.click).toBe('function')+        expect(Object.prototype.hasOwnProperty.call(e, 'tagName')).toBe(false)+        expect(Object.prototype.hasOwnProperty.call(e, 'click')).toBe(false)+        expect(+          `Prop "tagName" conflicts with an existing property on the custom element`,+        ).toHaveBeenWarned()+        expect(+          `Prop "click" conflicts with an existing property on the custom element`,+        ).toHaveBeenWarned()++        // props still work 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-PROPS')+      })++      test('should still pass props from vnodes', async () => {+        const tagName = ref('foo')+        const App = {+          render: () =>+            h('my-el-native-props', { tagName: tagName.value, click: 'bar' }),+        }+        render(h(App), container)+        const e = container.childNodes[0] as VueElement+        expect(e.tagName).toBe('MY-EL-NATIVE-PROPS')+        expect(e.shadowRoot!.innerHTML).toBe(`<div>foo|bar</div>`)+        expect(e.getAttribute('tag-name')).toBe('foo')++        tagName.value = 'baz'+        await nextTick()+        expect(e.shadowRoot!.innerHTML).toBe(`<div>baz|bar</div>`)+        expect(e.tagName).toBe('MY-EL-NATIVE-PROPS')+        expect(`Failed setting prop`).not.toHaveBeenWarned()+        expect(`Prop "tagName" conflicts`).toHaveBeenWarned()+        expect(`Prop "click" conflicts`).toHaveBeenWarned()+      })++      test('should still pass hyphenated props from vnodes', async () => {+        const tagName = ref('foo')+        const App = {+          render: () => h('my-el-native-props', { 'tag-name': tagName.value }),+        }+        render(h(App), container)+        const e = container.childNodes[0] as VueElement+        expect(e.shadowRoot!.innerHTML).toBe(`<div>foo|undefined</div>`)++        tagName.value = 'baz'+        await nextTick()+        expect(e.shadowRoot!.innerHTML).toBe(`<div>baz|undefined</div>`)+        expect(e.tagName).toBe('MY-EL-NATIVE-PROPS')+        expect(`Prop "tagName" conflicts`).toHaveBeenWarned()+        expect(`Prop "click" conflicts`).toHaveBeenWarned()+      })++      test('should drop pre-upgrade props shadowing native members', () => {+        const el = document.createElement('my-el-native-props-pre')+        ;(el as any).click = 'bar'+        customElements.define(+          'my-el-native-props-pre',+          defineCustomElement({+            props: { click: String },+            render() {+              return h('div', null, this.click)+            },+          }),+        )+        container.appendChild(el)+        expect(el.shadowRoot!.innerHTML).toBe(`<div>bar</div>`)+        expect(typeof el.click).toBe('function')+        expect(Object.prototype.hasOwnProperty.call(el, 'click')).toBe(false)+        expect(`Prop "click" conflicts`).toHaveBeenWarned()+      })+    })   })    describe('attrs', () => {@@ -2124,6 +2216,26 @@ describe('defineCustomElement', () => {         `[Vue warn]: Exposed property "value" already exists on custom element.`,       ).toHaveBeenWarned()     })++    test('should not override native element members via expose', () => {+      const E = defineCustomElement({+        setup(_, { expose }) {+          expose({+            tagName: 'exposed',+          })+          return () => h('div', null, 'hi')+        },+      })+      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(Object.prototype.hasOwnProperty.call(e, 'tagName')).toBe(false)+      expect(+        `[Vue warn]: Exposed property "tagName" already exists on custom element.`,+      ).toHaveBeenWarned()+    })   })    test('async & nested custom elements', async () => {packages/runtime-dom/src/apiCustomElement.tsindex 9422f58d6..f82c10b4e 100644@@ -35,7 +35,6 @@ import { import {   camelize,   extend,-  hasOwn,   hyphenate,   isArray,   isPlainObject,@@ -454,7 +453,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 to avoid shadowing native element+      // members (e.g. `tagName`, `click`)+      if (!(key in this)) {         // exposed properties are readonly         Object.defineProperty(this, key, {           // unwrap ref to be consistent with public instance behavior@@ -478,18 +479,44 @@ export class VueElement     }      // defining getter/setters on prototype+    const proto = Object.getPrototypeOf(this)     for (const key of declaredPropKeys.map(camelize)) {+      // avoid overriding members of the native element prototype chain+      // (e.g. `tagName`). The prop can still be set via its attribute or+      // vnode props (see patchProp).+      if (key in proto) {+        if (__DEV__) {+          warn(+            `Prop "${key}" conflicts with an existing property on the custom ` ++              `element and will not be defined as an element property. ` ++              `It can still be passed via the "${hyphenate(key)}" attribute ` ++              `or as a prop in Vue templates / render functions.`,+          )+        }+        // remove a pre-upgrade own property so it doesn't shadow the native one+        delete this[key as keyof this]+        continue+      }       Object.defineProperty(this, key, {         get(this: VueElement) {           return this._getProp(key)         },         set(this: VueElement, val) {-          this._setProp(key, val, true, !this._patching)+          this._setDeclaredProp(key, val)         },       })     }   } +  /**+   * Set a declared prop from outside (element property setter or vnode+   * patching).+   * @internal+   */+  _setDeclaredProp(key: string, val: any): void {+    this._setProp(key, val, true, !this._patching)+  }+   protected _setAttr(key: string): void {     if (key.startsWith('data-v-')) return     const has = this.hasAttribute(key)packages/runtime-dom/src/patchProp.tsindex 095a89403..4baa43cb7 100644@@ -40,6 +40,18 @@ export const patchProp: DOMRendererOptions['patchProp'] = (     if (!isModelListener(key)) {       patchEvent(el, key, prevValue, nextValue, parentComponent)     }+  } else if (+    // declared props of a Vue custom element that conflict with native+    // element members are not defined as element properties, so they must be+    // passed to the element directly+    (el as VueElement)._isVueCE &&+    key[0] !== '^' &&+    isNativeMemberPropForVueCE(el as VueElement, key)+  ) {+    ;(el as VueElement)._setDeclaredProp(+      camelize(key[0] === '.' ? key.slice(1) : key),+      nextValue,+    )   } else if (     key[0] === '.'       ? ((key = key.slice(1)), true)@@ -171,3 +183,11 @@ 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) {+  if (key[0] === '.') key = key.slice(1)+  return (+    camelize(key) in Object.getPrototypeOf(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)