Backtestsvuerun-20261001-022054#12124

Issue #12124 Merged fix PR #12125 Run 30 Sep 2026 · run-20261001-022054 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.

Both patches add a dev warning for prop names that collide with inherited element members. Patch A goes further and fixes the harmful part of the issue: when the colliding native member is read-only (e.g. `tagName`), it skips defining the accessor, so `Element.prototype.tagName` semantics are preserved. Its descriptor walk in `_isReadonlyNativeProp` decides this. The prop still works in both directions. The `tag-name` attribute maps to the prop, and Vue-rendered vnode props are routed through `_setProp` in `patchDOMProp`, so setting a getter-only property never fails. Writable conflicts such as `title` still get the accessor, with a warning. Patch A's tests cover the attribute path, the vnode-prop path (including no 'Failed setting prop' warning), and the writable-property case; each would fail before the change. Patch B only emits a warning and keeps overwriting. Its own test asserts `e.tagName === 'foo'`, which codifies the broken behavior the issue complains about: code relying on `tagName` breaks silently in production, where the warning is stripped. The issue does list a warning as an acceptable outcome, so B is minimally responsive. A is more invasive: it adds a per-call check in `patchDOMProp` for Vue CEs and a helper that scans `_def.props`. That cost is modest, well-gated by `_isVueCE` and the read-only check, and buys a real fix at the root cause rather than just surfacing the symptom. On correctness, A is clearly stronger.

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 34s16 turns

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

131vs 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+130 −1
packages/runtime-dom/__tests__/customElement.spec.tsindex 27c7121c2..48d344b11 100644@@ -683,6 +683,83 @@ describe('defineCustomElement', () => {       expect(prop1Calls).toBe(2)       expect(prop2Calls).toBe(1)     })++    test('prop named after a read-only native property should not override it', async () => {+      const E = defineCustomElement({+        props: {+          tagName: String,+        },+        render() {+          return h('div', this.tagName)+        },+      })+      customElements.define('my-el-tagname-prop', E)+      container.innerHTML = `<my-el-tagname-prop tag-name="foo"></my-el-tagname-prop>`+      const e = container.childNodes[0] as VueElement+      // native Element.prototype.tagName is preserved+      expect(e.tagName).toBe('MY-EL-TAGNAME-PROP')+      // attribute still maps to the prop+      expect(e.shadowRoot!.innerHTML).toBe('<div>foo</div>')++      e.setAttribute('tag-name', 'bar')+      await nextTick()+      expect(e.shadowRoot!.innerHTML).toBe('<div>bar</div>')+      expect(e.tagName).toBe('MY-EL-TAGNAME-PROP')++      expect(+        'Prop "tagName" conflicts with a read-only native property',+      ).toHaveBeenWarned()+    })++    test('prop named after a read-only native property via vnode props', async () => {+      const E = defineCustomElement({+        props: {+          tagName: String,+        },+        render() {+          return h('div', this.tagName)+        },+      })+      customElements.define('my-el-tagname-prop-vnode', E)+      render(h('my-el-tagname-prop-vnode', { tagName: 'foo' }), container)+      const e = container.childNodes[0] as VueElement+      // native Element.prototype.tagName is preserved+      expect(e.tagName).toBe('MY-EL-TAGNAME-PROP-VNODE')+      expect(e.shadowRoot!.innerHTML).toBe('<div>foo</div>')++      render(h('my-el-tagname-prop-vnode', { tagName: 'bar' }), container)+      await nextTick()+      expect(e.shadowRoot!.innerHTML).toBe('<div>bar</div>')+      expect(e.tagName).toBe('MY-EL-TAGNAME-PROP-VNODE')++      expect(+        'Prop "tagName" conflicts with a read-only native property',+      ).toHaveBeenWarned()+      expect('Failed setting prop').not.toHaveBeenWarned()+    })++    test('prop named after a writable native property still works as element property', async () => {+      const E = defineCustomElement({+        props: {+          title: String,+        },+        render() {+          return h('div', this.title)+        },+      })+      customElements.define('my-el-title-prop', E)+      container.innerHTML = `<my-el-title-prop></my-el-title-prop>`+      const e = container.childNodes[0] as VueElement & { title: string }+      expect(e.shadowRoot!.innerHTML).toBe('<div></div>')++      e.title = 'x'+      await nextTick()+      expect(e.shadowRoot!.innerHTML).toBe('<div>x</div>')++      expect(+        'Prop "title" overrides a native property of the element',+      ).toHaveBeenWarned()+    })   })    describe('attrs', () => {packages/runtime-dom/src/apiCustomElement.tsindex 9422f58d6..dc6554287 100644@@ -479,6 +479,18 @@ export class VueElement      // defining getter/setters on prototype     for (const key of declaredPropKeys.map(camelize)) {+      if (!hasOwn(this, key) && key in this) {+        // prop conflicts with an inherited (native) member+        const readonly = this._isReadonlyNativeProp(key)+        if (__DEV__) {+          warn(+            readonly+              ? `Prop "${key}" conflicts with a read-only native property of the element and will not be exposed as an element property. Its value can still be set via the corresponding attribute.`+              : `Prop "${key}" overrides a native property of the element.`,+          )+        }+        if (readonly) continue+      }       Object.defineProperty(this, key, {         get(this: VueElement) {           return this._getProp(key)@@ -490,6 +502,24 @@ export class VueElement     }   } +  /**+   * Whether `key` is an inherited native member of the element that has no+   * setter (e.g. `tagName`). Declared props with such names get no element+   * accessor, so they must be set via `_setProp` instead of `el[key] = value`.+   * @internal+   */+  _isReadonlyNativeProp(key: string): boolean {+    if (hasOwn(this, key) || !(key in this)) return false+    let proto = Object.getPrototypeOf(this)+    let desc: PropertyDescriptor | undefined+    while (proto && !(desc = Object.getOwnPropertyDescriptor(proto, key))) {+      proto = Object.getPrototypeOf(proto)+    }+    return (+      !!desc && (desc.get || desc.set ? !desc.set : desc.writable === false)+    )+  }+   protected _setAttr(key: string): void {     if (key.startsWith('data-v-')) return     const has = this.hasAttribute(key)packages/runtime-dom/src/modules/props.tsindex 98608831a..6caee659d 100644@@ -1,5 +1,5 @@ import { DeprecationTypes, compatUtils, warn } from '@vue/runtime-core'-import { includeBooleanAttr } from '@vue/shared'+import { camelize, includeBooleanAttr, isArray } from '@vue/shared' import { unsafeToTrustedHTML } from '../nodeOps'  // functions. The user is responsible for using them with only trusted content.@@ -54,6 +54,18 @@ export function patchDOMProp(     return   } +  // declared props of a Vue custom element that conflict with a read-only+  // native member (e.g. `tagName`) have no element accessor, so pass the+  // value to the component directly.+  if (+    el._isVueCE &&+    el._isReadonlyNativeProp(key) &&+    isDeclaredCEProp(el._def.props, key)+  ) {+    el._setProp(key, value, true, !el._patching)+    return+  }+   let needRemove = false   if (value === '' || value == null) {     const type = typeof el[key]@@ -109,3 +121,13 @@ export function patchDOMProp(   }   needRemove && el.removeAttribute(attrName || key) }++function isDeclaredCEProp(+  props: Record<string, unknown> | string[] | undefined,+  key: string,+): boolean {+  if (!props) return false+  return (isArray(props) ? props : Object.keys(props)).some(+    prop => camelize(prop) === 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) 

What the agent reported

A prop named after a read-only native member such as tagName no longer overrides it, and Vue now warns in dev when any prop name clashes with a native member. The new tests and the runtime-dom, vue and server-renderer suites all pass, and the type check is clean. All changes are uncommitted in the working tree.

What was wrong: VueElement._resolveProps (packages/runtime-dom/src/apiCustomElement.ts) added a getter/setter on the element for every declared prop, with no check. A tagName prop therefore hid Element.prototype.tagName, so el.tagName returned the prop value. Vue's own patchProp reads el.tagName too, so the override could affect Vue internally as well.

What I changed:

  1. apiCustomElement.ts, _resolveProps: before adding a prop's getter/setter, it checks whether the element already inherits a member with that name.
  2. Read-only natives (a getter with no setter, or a non-writable value, e.g. tagName): no element property is added, so the native one stays. The tag-name attribute still sets the prop. Dev warns: Prop "tagName" conflicts with a read-only native property of the element and will not be exposed….
  3. Writable natives (title, id, …): behaviour is unchanged. Dev warns: Prop "title" overrides a native property of the element.
  4. The prototype lookup lives in a new internal helper, _isReadonlyNativeProp.
  5. modules/props.ts, patchDOMProp: the reviewer found that step 1 alone broke a common case. When a Vue parent passes the prop (h('my-el', { tagName: 'foo' }) or tag-name="foo" in a template), Vue sets it as el.tagName = …. That hit the native getter, failed silently, and the component never got the value. Such declared props are now handed straight to the component (el._setProp).

Test evidence (3 new tests in the props block of packages/runtime-dom/__tests__/customElement.spec.ts):

  • tagName prop set by attribute (the reported case): e.tagName stays 'MY-EL-TAGNAME-PROP', the attribute renders foo then bar, and the warning fires. Without the fix it failed with expected 'foo' to be 'MY-EL-TAGNAME-PROP'.
  • tagName passed from a Vue parent: the native tagName is kept, foo and bar render, and there is no "Failed setting prop" warning. Without the props.ts change it failed with expected '<div></div>' to be '<div>foo</div>'.
  • title prop: setting e.title = 'x' still updates the component, and the new warning fires. Only the warning check failed without the fix.
  • Wider run: with the fix, ./bt-test packages/runtime-dom packages/vue packages/server-renderer gives 49 files, 701 passed, 1 skipped (an existing test.skip). Prettier and the type check are clean.

Things to know:

  • New dev warning for existing users: apps whose custom elements have props named title, id, hidden and so on will now see the "overrides a native property" warning. Their behaviour is unchanged. The warning repeats for every element instance.
  • Async components: if one has a read-only-named prop and a Vue parent sets it before the component definition has loaded, that first value is still dropped, because the declared props aren't known yet.

Requirements:

  1. Create only the tag-name attribute, with no tagName property: done for read-only natives. Covered by the attribute test and the Vue-parent test.
  2. Warn when a prop accidentally overrides an Element property: done, dev-only, for every clash. Covered by toHaveBeenWarned checks in all three tests.
  3. Lit-style option to map an attribute to a different property name: not done. It would be new public API, not a minimal fix. With item 1 the problem property is no longer overridden, and the attribute still reaches the prop, so the remapping isn't needed for this case.