Skip to content

fix(v-model): snapshot the assigned select value before invoking the assigner - #1

Merged
haoku123 merged 1 commit into
haoku123:fix/vmodel-select-set-syncfrom
ValentinYoushkevich:fix/vmodel-select-assigned-snapshot
Aug 17, 2026
Merged

haoku123 merged 1 commit into
haoku123:fix/vmodel-select-set-syncfrom
ValentinYoushkevich:fix/vmodel-select-assigned-snapshot

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown

Found one more way for the model and the DOM to fall out of sync while testing your branch for vuejs#15298: _assignedValue stores the same object that is handed to the change handler, so a handler that mutates the received value in place compares the value against itself and the override goes undetected.

Repro (fails on your branch head):

// handler enforces "bar is never allowed" by mutating the Set it received
'onUpdate:modelValue': (v: Set<string>) => {
  v.delete('bar')
  this.value = v
}

User selects foo + bar → model ends up {'foo'}, but bar stays selected in the DOM: in updated, value and _assignedValue are the same (mutated) Set, so assignedValueEquals returns true and setSelected is skipped.

Fix: snapshot Set/array values instead of storing the live reference — and take the snapshot before calling el[assignKey](...), because the assigner invokes the handler synchronously (snapshotting after the call captures the already-mutated value; that variant still fails the test).

Also added a regression test for clearing the model to null in the change handler — the original scenario from vuejs#10505 (it already passes on your branch, it just had no coverage).

Full runtime-dom suite passes (245 tests).

…assigner (vuejs#10505)

The updated-hook guard compared the model against the same object that was
handed to the change handler. A handler that mutates the received value in
place (e.g. Set#delete to enforce a constraint) therefore compared the value
with itself, the override went undetected and the DOM was left out of sync.

Snapshot Set/array values before calling the assigner (which runs the handler
synchronously), and add regression tests for in-place mutation and for
clearing the model to null - the original vuejs#10505 scenario.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants