Backtestsvuerun-20261021-133314#10505

Issue #10505 Merged fix PR #15298 Run 21 Oct 2026 · run-20261021-133314 vuejs/core

Clearing select's value in change handler behaviour changed since 3.4.15 via webdriver

Worse

The merged fix was judged better than our patch.

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

Both patches fix the root cause the same way: instead of blindly skipping `setSelected` while `_assigning` is set, `updated` now compares the model value against what the change listener assigned and re-syncs the DOM when they differ. Both pass all six independent tests, including the single-select-cleared-to-null case from the issue, the fixed-value reset, and the multiple-select reset/in-place mutation cases.

Patch A is the more robust implementation. It compares with `looseEqual`/Set membership, which is the same equality `setSelected` itself uses, so a handler that replaces the model with an equal-but-new array still takes the fast path; Patch B uses `toRaw` identity, which forces a full option rewrite in that case, undermining the perf optimization the original commit introduced. A also clears the pending marker as soon as `updated` consumes it (so any further update in the same tick always syncs), detects `el.multiple` flipping during the pending update, snapshots the Array it hands to user code, and uses try/finally so a throwing assigner cannot leave stale state. B's snapshot/`_assigning` combination is correct for the scenarios in the issue but keeps three parallel fields and leaves `_assigning` semantics overloaded.

On tests, A adds a broader suite (single clear, Set override, duplicate values, multiple→single, Array/Set mutation in handler, no-rewrite guards, assigner throw), all of which exercise real behaviour rather than tautologies. B's five tests are well targeted at the issue (including the 0/1 values from the report) and include a no-re-sync regression guard, but cover fewer edges.

On craft, B is simpler and closer to the surrounding code, and its comment is clearer; A's tuple with `pending[0]`/`pending[1]` indexing is less readable. That readability cost is real but smaller than A's correctness and consistency advantages, so A wins by a moderate 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

6m 23s

Wall-clock time in the container

Full test suite

No new failures

708 passed · 1 skipped · 709 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

243vs 345 merged

Changed lines, ours vs merged

Vue version

3.4.21

Link to minimal reproduction

https://play.vuejs.org/#eNp9Uk1P4zAQ/SuzvtBKkO5q91SllXYRh+VAEXACc4iSSWtwbMsfoVLIf2ds00IRkEMSz3sz8+Z5BvbXmKIPyOas9NgZWXlccgVQOpRYe+hPOt2gXHCWA0IrziJh9/QnWs3rTaXWSCT6NhJX6jQFOEu1qJo2MRP6SoZI+0nILVpdzjLwBe0X0VYKD1jlLAvJB0P9W22jPBAKMoQN5Q0DOBjHcmaIWc7eDUdHV1thPEgSSanecUapPkSq6Iy2Hgaw2MIIrdUdHJFDRzGx1sr51y5R6CKySuetUGt4BhWkXE7ie3rIxeaAene/nNzdE4erNqhc6tA5mEzn0GvRwBDnFC1M9l2LZA/8WCxSw2mmwL5VxgsT3OZjErUEGOPrY7VciysCyeFkz5IdkzU0RivWxYPTipYkteKs1p0REu0q3QvZN9+J4KySUj+dp5i3AY938XqD9eMn8Qe3jTHOLi06tD1tzR7zlV2jz/DZ9QVu6X8P0mIGSexvwCt0Woa8tJH2L0ST7TteUvs/3TldzI0723pUbjdUFJosS3zOaA9Ovxn9Te7v4s+r1SMbXwCvMCS3

Steps to reproduce

👋 sorry I can only reproduce this myself when acting on chrome with webdriver, but I have narrowed it down a lot

the basic premise is we have a strange select that clears its value on change, exampled in the repo link

The bug occurs when _webdriver_ clicks the select and clicks one of the options within the value does not get cleared afterwards. If I click in the page myself it clears properly.

What is expected?

The value of the select afterwards should be null

What is actually happening?

it is whatever was selected last, ie 0 or 1

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
    Memory: 55.80 GB / 88.39 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
  Browsers:
    Chrome: 122.0.6261.94

Any additional comments?

I have bisected the releases and found that this first happens from 3.4.15. I suspect the change is related to the select performance improvement https://github.com/vuejs/core/commit/2ffb956efe692da059f4895669084c5278871351

further i notice the commit introduces and _assigning field which changes the behaviour until the next tick. and wrapping the clearing call in nextTick works as a workaround in my instance.

  nextTick(() => { selection.value = null })

I suspect the issue relates to the fact that webdriver submits selection events in a slightly unusual manner. However I think that shouldn't mean this broke but it has

The two patches

Our patch+235 −8
packages/runtime-dom/__tests__/directives/vModel.spec.tsindex 590c0d7df..a96f2ec2a 100644@@ -1365,6 +1365,205 @@ describe('vModel', () => {     expect(data.value).toMatchObject(['bar'])   }) +  it('select should sync DOM when model is reset in change handler', async () => {+    const component = defineComponent({+      data() {+        return { value: null as any }+      },+      render() {+        return [+          withVModel(+            h(+              'select',+              {+                'onUpdate:modelValue': setValue.bind(this),+                onChange: () => {+                  this.value = null+                },+              },+              [h('option', { value: 0 }), h('option', { value: 1 })],+            ),+            this.value,+          ),+        ]+      },+    })+    render(h(component), root)++    const input = root.querySelector('select')+    const data = root._vnode.component.data+    expect(input.selectedIndex).toEqual(-1)++    input.selectedIndex = 1+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toEqual(null)+    expect(input.selectedIndex).toEqual(-1)+    expect(input.value).toEqual('')++    input.selectedIndex = 0+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toEqual(null)+    expect(input.selectedIndex).toEqual(-1)+  })++  it('select should sync DOM when model is changed to another value in change handler', async () => {+    const component = defineComponent({+      data() {+        return { value: 'foo' }+      },+      render() {+        return [+          withVModel(+            h(+              'select',+              {+                'onUpdate:modelValue': setValue.bind(this),+                onChange: () => {+                  this.value = 'foo'+                },+              },+              [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+    expect(foo.selected).toEqual(true)++    // model goes 'foo' -> 'bar' -> 'foo' within the same tick+    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toEqual('foo')+    expect(foo.selected).toEqual(true)+    expect(bar.selected).toEqual(false)+  })++  it('multiple select should sync DOM when model is reset in change handler', async () => {+    const component = defineComponent({+      data() {+        return { value: [] as any[] }+      },+      render() {+        return [+          withVModel(+            h(+              'select',+              {+                multiple: true,+                'onUpdate:modelValue': setValue.bind(this),+                onChange: () => {+                  this.value = []+                },+              },+              [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+    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toMatchObject([])+    expect(foo.selected).toEqual(false)+    expect(bar.selected).toEqual(false)+  })++  it('multiple select should sync DOM when model is mutated in change handler', async () => {+    const component = defineComponent({+      data() {+        return { value: [] as any[] }+      },+      render() {+        return [+          withVModel(+            h(+              'select',+              {+                multiple: true,+                'onUpdate:modelValue': setValue.bind(this),+                onChange: () => {+                  this.value.splice(0)+                },+              },+              [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+    bar.selected = true+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toMatchObject([])+    expect(foo.selected).toEqual(false)+    expect(bar.selected).toEqual(false)+  })++  it('select should not re-sync DOM after its own assignment', async () => {+    const component = defineComponent({+      data() {+        return { value: [] as any[] }+      },+      render() {+        return [+          withVModel(+            h(+              'select',+              {+                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 data = root._vnode.component.data+    const spy = vi.spyOn(foo, 'selected', 'set')++    foo.selected = true+    spy.mockClear()+    triggerEvent('change', input)+    await nextTick()+    expect(data.value).toMatchObject(['foo'])+    expect(spy).not.toHaveBeenCalled()+  })+   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 eeb248f28..5e1e5e14c 100644@@ -4,6 +4,7 @@ import {   type ObjectDirective,   type VNode,   nextTick,+  toRaw,   warn, } from '@vue/runtime-core' import { addEventListener } from '../modules/events'@@ -45,6 +46,8 @@ type ModelDirective<T, Modifiers extends string = string> = ObjectDirective<     [assignKey]: AssignerFn     [initialValueKey]?: string     _assigning?: boolean+    _assignedValue?: any+    _assignedSnapshot?: any[]   },   any,   Modifiers@@ -240,16 +243,22 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {         .map((o: HTMLOptionElement) =>           number ? looseToNumber(getValue(o)) : getValue(o),         )-      el[assignKey](-        el.multiple-          ? isSet((el as any)._modelValue)-            ? new Set(selectedVal)-            : selectedVal-          : selectedVal[0],-      )+      const assignedValue = el.multiple+        ? isSet((el as any)._modelValue)+          ? new Set(selectedVal)+          : selectedVal+        : selectedVal[0]+      el[assignKey](assignedValue)+      // remember what we assigned so that the skip in `updated` only applies+      // while the model still holds exactly that value. If it is replaced or+      // mutated in the same tick (e.g. reset in a user @change handler), the+      // DOM must be re-synced.       el._assigning = true+      el._assignedValue = toRaw(assignedValue)+      el._assignedSnapshot = el.multiple ? selectedVal.slice() : undefined       nextTick(() => {         el._assigning = false+        el._assignedValue = el._assignedSnapshot = undefined       })     })     el[assignKey] = getModelAssigner(vnode)@@ -264,12 +273,31 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {     el[assignKey] = getModelAssigner(vnode)   },   updated(el, { value }) {-    if (!el._assigning) {+    if (!el._assigning || !isAssignedValue(el, value)) {       setSelected(el, value)     }   }, } +function isAssignedValue(+  el: HTMLSelectElement & {+    _assignedValue?: any+    _assignedSnapshot?: any[]+  },+  value: any,+): boolean {+  const raw = toRaw(value)+  if (raw !== el._assignedValue) return false+  const snapshot = el._assignedSnapshot+  if (!snapshot) return true+  // same Array / Set instance - make sure it was not mutated in place+  const current: any[] = isSet(raw) ? Array.from(raw) : raw+  return (+    current.length === snapshot.length &&+    current.every((v, i) => v === snapshot[i])+  )+}+ function setSelected(el: HTMLSelectElement, value: any) {   const isMultiple = el.multiple   const isArrayValue = isArray(value) 
Merged fix · PR #15298+333 −12
packages/runtime-dom/__tests__/directives/vModel.spec.tsindex 590c0d7df..429163126 100644@@ -1317,6 +1317,290 @@ describe('vModel', () => {     expect(bar.selected).toEqual(true)   }) +  function mountSelectModel(+    initialValue: any,+    update: (value: any) => any,+    multiple = false,+    optionValues: any[] = ['foo', 'bar'],+  ) {+    const component = defineComponent({+      data: () => ({ value: initialValue }),+      render() {+        return withVModel(+          h(+            'select',+            {+              multiple,+              'onUpdate:modelValue': (value: any) => {+                this.value = update(value)+              },+            },+            optionValues.map(value => h('option', { value })),+          ),+          this.value,+        )+      },+    })+    render(h(component), root)+    const input = root.querySelector('select') as HTMLSelectElement+    return { input, options: input.options, data: root._vnode.component.data }+  }++  function trackSelectedWrites(input: HTMLSelectElement) {+    const selected = Object.getOwnPropertyDescriptor(+      HTMLOptionElement.prototype,+      'selected',+    )!+    let writes = 0+    for (const option of input.options) {+      Object.defineProperty(option, 'selected', {+        configurable: true,+        get: selected.get,+        set(value) {+          writes+++          selected.set!.call(this, value)+        },+      })+    }+    return () => writes+  }++  it('should sync a multiple select when the Set model is overridden', async () => {+    const { input, options, data } = mountSelectModel(+      new Set<string>(),+      () => new Set(['foo']),+      true,+    )+    const foo = options[0]+    const bar = options[1]++    bar.selected = true+    triggerEvent('change', input)+    await nextTick()++    expect(Array.from(data.value)).toEqual(['foo'])+    expect(foo.selected).toBe(true)+    expect(bar.selected).toBe(false)+  })++  it('should clear a single select when a native change handler clears the model', async () => {+    const component = defineComponent({+      data() {+        return { value: null as string | null }+      },+      render() {+        return withVModel(+          h(+            'select',+            {+              'onUpdate:modelValue': setValue.bind(this),+              onChange: () => {+                this.value = null+              },+            },+            [h('option', { value: 'foo' }), h('option', { value: 'bar' })],+          ),+          this.value,+        )+      },+    })+    render(h(component), root)+    const input = root.querySelector('select') as HTMLSelectElement+    const data = root._vnode.component.data++    input.options[1].selected = true+    triggerEvent('change', input)+    await nextTick()++    expect(data.value).toBe(null)+    expect(input.selectedIndex).toBe(-1)+  })++  it('should preserve the selected option when duplicate values exist', async () => {+    const { input, options, data } = mountSelectModel(+      null,+      value => value,+      false,+      ['foo', 'foo'],+    )++    options[1].selected = true+    triggerEvent('change', input)+    await nextTick()++    expect(data.value).toBe('foo')+    expect(input.selectedIndex).toBe(1)+  })++  it('should resync when a multiple select becomes single during the pending update', async () => {+    const component = defineComponent({+      data() {+        return { value: [] as string[], multiple: true }+      },+      render() {+        return withVModel(+          h(+            'select',+            {+              multiple: this.multiple,+              'onUpdate:modelValue': (value: string[]) => {+                this.value = value+                this.multiple = false+              },+            },+            [h('option', { value: 'foo' }), h('option', { value: 'bar' })],+          ),+          this.value,+        )+      },+    })+    render(h(component), root)+    const input = root.querySelector('select') as HTMLSelectElement+    const data = root._vnode.component.data++    input.options[1].selected = true+    triggerEvent('change', input)+    await nextTick()++    expect(data.value).toEqual(['bar'])+    expect(input.multiple).toBe(false)+    expect(input.selectedIndex).toBe(-1)+  })++  it('should snapshot an emitted Array before the change handler mutates it', async () => {+    const { input, options, data } = mountSelectModel(+      ['foo'],+      (value: string[]) => {+        value.pop()+        return value+      },+      true,+    )+    const foo = options[0]+    const bar = options[1]++    foo.selected = true+    bar.selected = true+    triggerEvent('change', input)+    await nextTick()++    expect(data.value).toEqual(['foo'])+    expect(foo.selected).toBe(true)+    expect(bar.selected).toBe(false)+  })++  it('should resync after the emitted Set is mutated in the change handler', async () => {+    const { input, options, data } = mountSelectModel(+      new Set(['foo']),+      (value: Set<string>) => {+        value.delete('bar')+        return value+      },+      true,+    )+    const foo = options[0]+    const bar = options[1]++    foo.selected = true+    bar.selected = true+    triggerEvent('change', input)+    await nextTick()++    expect(Array.from(data.value)).toEqual(['foo'])+    expect(foo.selected).toBe(true)+    expect(bar.selected).toBe(false)+  })++  it('should not rewrite options after assigning a Set of objects', async () => {+    const fooValue = { id: 'foo' }+    const barValue = { id: 'bar' }+    const { input, options } = mountSelectModel(+      new Set([fooValue]),+      value => value,+      true,+      [fooValue, barValue],+    )++    options[0].selected = false+    options[1].selected = true+    const getWrites = trackSelectedWrites(input)+    triggerEvent('change', input)+    await nextTick()++    expect(getWrites()).toBe(0)+  })++  it('should not rewrite options after assigning an Array of objects', async () => {+    const fooValue = { id: 'foo' }+    const barValue = { id: 'bar' }+    const { input, options } = mountSelectModel([], value => value, true, [+      fooValue,+      barValue,+    ])++    options[1].selected = true+    const getWrites = trackSelectedWrites(input)+    triggerEvent('change', input)+    await nextTick()++    expect(getWrites()).toBe(0)+  })++  it('should not rewrite options for a primitive Array model', async () => {+    const optionValues = Array.from({ length: 10 }, (_, i) => i)+    const { input, options, data } = mountSelectModel(+      [],+      value => value,+      true,+      optionValues,+    )++    for (let i = 0; i < 5; i++) options[i].selected = true+    const getWrites = trackSelectedWrites(input)+    triggerEvent('change', input)+    await nextTick()++    expect(data.value).toHaveLength(5)+    expect(getWrites()).toBe(0)+  })++  it('should clear the pending assignment when the assigner throws', async () => {+    const error = new Error('assign failed')+    const component = defineComponent({+      data: () => ({ value: [] }),+      render() {+        return withVModel(+          h(+            'select',+            {+              multiple: true,+              'onUpdate:modelValue': () => {+                throw error+              },+            },+            [h('option', { value: 'foo' }), h('option', { value: 'bar' })],+          ),+          this.value,+        )+      },+    })+    render(h(component), root)+    const input = root.querySelector('select') as HTMLSelectElement+    const onError = vi.fn((event: ErrorEvent) => event.preventDefault())+    window.addEventListener('error', onError)++    try {+      input.options[1].selected = true+      triggerEvent('change', input)+      await nextTick()++      expect(onError).toHaveBeenCalled()+      expect((input as any)._pendingValue).toBeUndefined()+    } finally {+      window.removeEventListener('error', onError)+    }+  })+   it('multiple select uses current Array/Set model type', async () => {     const component = defineComponent({       data() {packages/runtime-dom/src/directives/vModel.tsindex eeb248f28..041f17c5a 100644@@ -44,7 +44,7 @@ type ModelDirective<T, Modifiers extends string = string> = ObjectDirective<   T & {     [assignKey]: AssignerFn     [initialValueKey]?: string-    _assigning?: boolean+    _pendingValue?: [multiple: boolean, value: any]   },   any,   Modifiers@@ -240,17 +240,31 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {         .map((o: HTMLOptionElement) =>           number ? looseToNumber(getValue(o)) : getValue(o),         )-      el[assignKey](-        el.multiple-          ? isSet((el as any)._modelValue)-            ? new Set(selectedVal)+      const multiple = el.multiple+      const assignedValue = multiple+        ? isSet((el as any)._modelValue)+          ? new Set(selectedVal)+          : selectedVal+        : selectedVal[0]+      // Array models receive selectedVal directly, so snapshot it before user+      // code can mutate it. Set models already receive a fresh Set.+      const pending = (el._pendingValue = [+        multiple,+        multiple+          ? isArray(assignedValue)+            ? selectedVal.slice()             : selectedVal-          : selectedVal[0],-      )-      el._assigning = true-      nextTick(() => {-        el._assigning = false-      })+          : assignedValue,+      ])+      try {+        el[assignKey](assignedValue)+      } finally {+        nextTick(() => {+          if (el._pendingValue === pending) {+            el._pendingValue = undefined+          }+        })+      }     })     el[assignKey] = getModelAssigner(vnode)   },@@ -264,12 +278,35 @@ export const vModelSelect: ModelDirective<HTMLSelectElement, 'number'> = {     el[assignKey] = getModelAssigner(vnode)   },   updated(el, { value }) {-    if (!el._assigning) {+    const pending = el._pendingValue+    el._pendingValue = undefined+    if (+      !pending ||+      pending[0] !== el.multiple ||+      !isSameSelectValue(value, pending[1], pending[0])+    ) {       setSelected(el, value)     }   }, } +function isSameSelectValue(+  value: any,+  assignedValue: any,+  multiple: boolean,+): boolean {+  if (!multiple) return looseEqual(value, assignedValue)+  if (isArray(value)) return looseEqual(value, assignedValue)+  if (isSet(value)) {+    if (value.size !== assignedValue.length) return false+    for (const item of assignedValue) {+      if (!value.has(item)) return false+    }+    return true+  }+  return false+}+ function setSelected(el: HTMLSelectElement, value: any) {   const isMultiple = el.multiple   const isArrayValue = isArray(value)