defineModel on Firefox does not work as expected Vue version 3.5.17 Link to minimal…
- User
defineModel on Firefox does not work as expected
Vue version
3.5.17
Link to minimal reproduction
Steps to reproduce
- Use firefox
- Enter anything in the field. It should be blocked and only show "a", but it wont on firefox.
What is expected?
It should only keep "a" and nothing else should "make it through"
What is actually happening?
Seems like either a race condition or firefox not updating at the same time as Chrome? no clue.
System Info
System: OS: Windows 11 10.0.26100 CPU: (20) x64 Intel(R) Core(TM) i5-14600K Memory: 12.60 GB / 31.77 GB Binaries: Node: 22.16.0 - C:\nvm4w\nodejs\node.EXE npm: 10.9.2 - C:\nvm4w\nodejs\npm.CMD Browsers: Edge: Chromium (134.0.3124.85) Internet Explorer: 11.0.26100.1882 -- Its not showing my actual browser: Firefox 139.0.4Any additional comments?
No response
Interface
No new interfaces are introduced.
- Assistant
Investigating the
defineModelFirefox issue by exploring the repository and how model updates are handled. - Assistant
Tracing the issue: when the model stays
'a'but the DOM has extra characters, no re-render runs sovModelbeforeUpdatenever syncs the input. Verifying and implementing the fix. - Assistant
Extending the #10279 fix: when v-model assigns the raw input then a handler resets to the same emitted value, the parent doesn't re-render and the DOM stays out of sync.
- Assistant
Cause
With
defineModel()on an<input v-model="model" @input="...">, each keystroke runs two updates in one nativeinputevent:- The
v-modeldirective assigns the rawel.value(e.g."ab"). - Your
@inputhandler setsmodel.valueback to"a".
The parent ends up with
"a", so the prop does not change.useModeltherefore skips a re-render, andvModelText’sbeforeUpdatenever runs to resetel.value. The field can keep showing extra characters. That shows up more often in Firefox because of event/timing differences, but the underlying issue is the missing forced update inuseModel.Fix
In
packages/runtime-core/src/helpers/useModel.ts, extend the existing #10279 “force local update” logic: when the emitted value already matches but the new set value differs from the previous one in the same input turn (v-model then handler), call so the DOM is synced via ’s . - The
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.