Backtestsvuerun-20261009-161443#15009

Issue #15009 Merged fix PR #15010 Run 9 Oct 2026 · run-20261009-161443 vuejs/core

v-model on <select multiple> uses stale collection type after switching between Array and Set

Better

Our patch was judged better than the merged fix.

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

Both patches apply the same root-cause fix. They store the current model value on the element in `created` and refresh it in `beforeUpdate`, and the change listener calls `isSet(el._modelValue)` at event time instead of using the stale `isSetModel` captured at creation. Correctness is equivalent: both handle Array->Set and Set->Array switches and keep `el.multiple` semantics unchanged. Both tests would fail before the fix and pass after, since the first change event after a runtime switch would emit the old type. Patch A's test is slightly stronger. After each switch it also asserts that the DOM `selected` state was synced to the new model before the user interaction, and its interaction modifies only one option, which mirrors a real user action. Patch B forces both options' selected states manually and skips those checks. On craft, Patch A is clearly better. It adds `_modelValue?: any` to the `ModelDirective` element type, matching how `_assigning` is declared, and adds a short explanatory comment. Patch B uses repeated `(el as any)` casts with leading-semicolon statements, which is less consistent with the surrounding typed code. Scope is minimal and equal for both. Patch A wins on test thoroughness and type-safe consistency.

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

3m 42s

Wall-clock time in the container

Full test suite

No new failures

681 passed · 1 skipped · 682 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

65vs 55 merged

Changed lines, ours vs merged

Vue version

3.5.39

Link to minimal reproduction

https://play.vuejs.org/#__PROD__eNp9Uk1P4zAQ/SuWLwWJTQ/dPSwK1X6Iw+4BEHDDCAV3UgyObdnjtFKU/86MQwtIwMWK57158+bFg/wdQtVnkMeyTjqagCIB5rBUznTBRxSDiNCKUbTRd2JG1JlyymnvElMtaISVOGHSwc3tIWNtdhqNdyJtDOqHa38FeHAoBuXEvqPqG5uB+hxsBOM3s9b7GQuMytXzyQu5oAtCF2yDQDch6vuMSNq/tDX66UTJN0OUXE43gZ5F6/lELjLUOg0X/bfOr8By74sbJUWXLZpgpyHE9aGsUGwSk8yROp31fEI+4d03kXh0vuPRPmXSzkiIsByG3fRxrOdc4b33u8ojiYlSbs26ekze0Q8qASqpfReMhXhe9JOSx1O0jDXW+s3/UsOY4WhX1w+gnz6oP6Yt15S8iJAg9qDkHsMmrjlThk+vzmBL33uQEsyW2F+Al5C8zexxov3JbkW23/CK23/lmRm3vk6nWwSXdkuxUWaOha8kPb2/X6z+andRfS999JQoxbseImtSgIvqR7X4Kcdnt8MAPA==

Steps to reproduce

  1. Bind a <select multiple v-model> to an Array.
  2. Switch the bound value to a Set at runtime.
  3. Interact with the select again.
  4. The emitted model becomes an Array again.
  5. Switching back from Set -> Array shows the same stale-type behavior in reverse.

What is expected?

The current collection type should be respected after the model switches at runtime.

What is actually happening?

The change handler keeps using the collection type captured when the directive was created, so the first user interaction after a runtime Array/Set switch emits the old type.

System Info

Any additional comments?

_No response_

The two patches

Our patch+61 −4
packages/runtime-dom/__tests__/directives/vModel.spec.tsindex 2b78b0c61..5e9a4a14f 100644@@ -1317,6 +1317,60 @@ describe('vModel', () => {     expect(bar.selected).toEqual(true)   }) +  it('multiple select (model switches between Array and Set at runtime)', async () => {+    const component = defineComponent({+      data() {+        return { value: [] as any }+      },+      render() {+        return [+          withVModel(+            h(+              'select',+              {+                value: null,+                multiple: true,+                'onUpdate:modelValue': setValue.bind(this),+              },+              [h('option', { value: 'foo' }), h('option', { value: 'bar' })],+            ),+            this.value,+          ),+        ]+      },+    })+    render(h(component), root)++    const input = root.querySelector('select')+    const foo = root.querySelector('option[value=foo]')+    const bar = root.querySelector('option[value=bar]')+    const data = root._vnode.component.data++    // Array -> Set+    data.value = new Set(['foo'])+    await nextTick()+    expect(foo.selected).toEqual(true)+    expect(bar.selected).toEqual(false)++    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Set)+    expect(data.value).toMatchObject(new Set(['foo', 'bar']))++    // Set -> Array+    data.value = ['bar']+    await nextTick()+    expect(foo.selected).toEqual(false)+    expect(bar.selected).toEqual(true)++    foo.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(Array.isArray(data.value)).toBe(true)+    expect(data.value).toMatchObject(['foo', 'bar'])+  })+   it('multiple select (model is Set, option value is object)', async () => {     const fooValue = { foo: 1 }     const barValue = { bar: 1 }packages/runtime-dom/src/directives/vModel.tsindex b49bf809e..d6643a5df 100644@@ -40,7 +40,7 @@ function onCompositionEnd(e: Event) { const assignKey: unique symbol = Symbol('_assign')  type ModelDirective<T, Modifiers extends string = string> = ObjectDirective<-  T & { [assignKey]: AssignerFn; _assigning?: boolean },+  T & { [assignKey]: AssignerFn; _assigning?: boolean; _modelValue?: any },   any,   Modifiers >@@ -207,7 +207,9 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {   // <select multiple> value need to be deep traversed   deep: true,   created(el, { value, modifiers: { number } }, vnode) {-    const isSetModel = isSet(value)+    // store the v-model value on the element so the change listener always+    // emits the current collection type (Array or Set)+    el._modelValue = value     addEventListener(el, 'change', () => {       const selectedVal = Array.prototype.filter         .call(el.options, (o: HTMLOptionElement) => o.selected)@@ -216,7 +218,7 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {         )       el[assignKey](         el.multiple-          ? isSetModel+          ? isSet(el._modelValue)             ? new Set(selectedVal)             : selectedVal           : selectedVal[0],@@ -233,8 +235,9 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {   mounted(el, { value }) {     setSelected(el, value)   },-  beforeUpdate(el, _binding, vnode) {+  beforeUpdate(el, { value }, vnode) {     el[assignKey] = getModelAssigner(vnode)+    el._modelValue = value   },   updated(el, { value }) {     if (!el._assigning) { 
Merged fix · PR #15010+52 −3
packages/runtime-dom/__tests__/directives/vModel.spec.tsindex 2b78b0c61..590c0d7df 100644@@ -1317,6 +1317,54 @@ describe('vModel', () => {     expect(bar.selected).toEqual(true)   }) +  it('multiple select uses current Array/Set model type', async () => {+    const component = defineComponent({+      data() {+        return { value: [] }+      },+      render() {+        return [+          withVModel(+            h(+              'select',+              {+                value: null,+                multiple: true,+                'onUpdate:modelValue': setValue.bind(this),+              },+              [h('option', { value: 'foo' }), h('option', { value: 'bar' })],+            ),+            this.value,+          ),+        ]+      },+    })+    render(h(component), root)++    const input = root.querySelector('select')+    const foo = root.querySelector('option[value=foo]')+    const bar = root.querySelector('option[value=bar]')+    const data = root._vnode.component.data++    data.value = new Set(['foo'])+    await nextTick()+    foo.selected = true+    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Set)+    expect(data.value).toMatchObject(new Set(['foo', 'bar']))++    data.value = ['foo']+    await nextTick()+    foo.selected = false+    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(Array.isArray(data.value)).toBe(true)+    expect(data.value).toMatchObject(['bar'])+  })+   it('multiple select (model is Set, option value is object)', async () => {     const fooValue = { foo: 1 }     const barValue = { bar: 1 }packages/runtime-dom/src/directives/vModel.tsindex b49bf809e..766db6bfe 100644@@ -207,7 +207,7 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {   // <select multiple> value need to be deep traversed   deep: true,   created(el, { value, modifiers: { number } }, vnode) {-    const isSetModel = isSet(value)+    ;(el as any)._modelValue = value     addEventListener(el, 'change', () => {       const selectedVal = Array.prototype.filter         .call(el.options, (o: HTMLOptionElement) => o.selected)@@ -216,7 +216,7 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {         )       el[assignKey](         el.multiple-          ? isSetModel+          ? isSet((el as any)._modelValue)             ? new Set(selectedVal)             : selectedVal           : selectedVal[0],@@ -233,7 +233,8 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {   mounted(el, { value }) {     setSelected(el, value)   },-  beforeUpdate(el, _binding, vnode) {+  beforeUpdate(el, { value }, vnode) {+    ;(el as any)._modelValue = value     el[assignKey] = getModelAssigner(vnode)   },   updated(el, { value }) {