Backtestsvuerun-20261021-133314#15009

Issue #15009 Merged fix PR #15010 Run 21 Oct 2026 · run-20261021-133314 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 B = our agent, Patch A = the merged fix.

The source changes are byte-identical: both patches replace the `isSetModel` captured in `created` with an `el._modelValue` field that is initialized in `created` and refreshed in `beforeUpdate`, so the change handler reads the current model type. This correctly fixes the root cause (stale closure capture) and all five independent tests pass identically for A and B. The only difference is the test coverage. Patch A adds one test that starts from an Array, switches to a Set, then back to an Array, checking the emitted type each time. Patch B adds two tests, one starting from Array and one from Set, each performing an interaction before the switch (matching the issue's 'interact with the select again' scenario), verifying that setSelected reflects the new model after the switch, and then switching back. B's tests more faithfully cover both directions described in the issue (steps 2-4 and step 5) and exercise the case where the handler had already run with the old type. Both test sets would fail before and pass after the fix. Scope and craft are equal otherwise, so B wins on test thoroughness by a modest margin.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

3m 29s

Wall-clock time in the container

Full test suite

No new failures

682 passed · 1 skipped · 683 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

121vs 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+118 −3
packages/runtime-dom/__tests__/directives/vModel.spec.tsindex 2b78b0c61..6b4dac5d9 100644@@ -1317,6 +1317,120 @@ describe('vModel', () => {     expect(bar.selected).toEqual(true)   }) +  it('multiple select (model switches from Array to 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++    foo.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Array)++    data.value = new Set(['bar'])+    await nextTick()+    expect(foo.selected).toEqual(false)+    expect(bar.selected).toEqual(true)++    foo.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Set)+    expect(data.value).toMatchObject(new Set(['foo', 'bar']))++    data.value = []+    await nextTick()+    expect(foo.selected).toEqual(false)+    expect(bar.selected).toEqual(false)++    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Array)+    expect(data.value).toMatchObject(['bar'])+  })++  it('multiple select (model switches from Set to Array at runtime)', async () => {+    const component = defineComponent({+      data() {+        return { value: new Set() 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++    foo.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Set)++    data.value = ['bar']+    await nextTick()+    expect(foo.selected).toEqual(false)+    expect(bar.selected).toEqual(true)++    foo.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Array)+    expect(data.value).toMatchObject(['foo', 'bar'])++    data.value = new Set()+    await nextTick()+    expect(foo.selected).toEqual(false)+    expect(bar.selected).toEqual(false)++    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toBeInstanceOf(Set)+    expect(data.value).toMatchObject(new Set(['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 }) { 
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 }) {