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
shellSystem: 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 Vue's
defineModelimplementation and Firefox-specific input handling. - Assistant
Identifying a race: when
v-modeland@inputshare an element, handler order can letv-modeloverwrite a constrained value (especially in Firefox). Deferringv-model's input assignment to a microtask so@inputruns first. - Assistant
Implementing the useModel fix: triggering a sync when assigning the same value so the DOM can resync before v-model's input handler runs.
- Assistant
Reverting the useModel change: Vue flushes updates asynchronously, so that approach won't sync the DOM before v-model's handler. Deferring v-model assignment with
nextTickinstead. - Assistant
Deferring v-model assignment only when other Vue
inputlisteners exist, preserving synchronous behavior for plain v-model. - Assistant
Restoring the useModel
trigger()on early return so same-value assignments still sync the DOM before deferred v-model readsel.value. - Assistant
Using capture phase so v-model runs before
@inputlisteners, matching expected behavior for both cases. - Assistant
Cause
The repro uses both
v-modeland@inputon the same<input>. The intended flow is:v-modelreadsel.valueand updates the model.@inputconstrains the model (always'a').
That only works if step 1 runs before step 2. Listener order is registration-dependent; in Firefox the user
@inputhandler could run first. ThendefineModel’s setter could no-op when the value was already'a', andv-modelwould still assign the raw input text afterward.Fix
Register the native
v-modelinputlistener in the capture phase so it always runs before bubble-phase handlers like@input, regardless of browser or registration order:64:72:packages/runtime-dom/src/directives/vModel.ts
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.