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
defineModelbehavior and Firefox-specific v-model handling in the Vue repository. - Assistant
Implementing capture-phase registration for v-model's input listener so it runs before user
@inputhandlers (Firefox registers listeners in a different order than Chrome). - Assistant
Cause
defineModelon a child with parentv-modeldoes not update the local ref synchronously; it only emits and waits for the prop to come back. On<input v-model="model" @input="onInput" />there are two listeners:- v-model (directive) — native
inputlistener that assigns fromel.value @input— Vue’s invoker (e.g. forcingmodel.value = 'a')
If the v-model listener runs after
@input, it reads the DOM again and emits the typed value, undoing the handler. Chrome and Firefox differ in listener order, so the bug shows up mainly on Firefox.Fix
Register v-model’s assign listener in the capture phase so it always runs before bubble-phase
@inputhandlers, while user handlers still run last and win.// Use capture phase so v-model updates before user onInput handlers. // Otherwise browsers may invoke listeners in different orders (e.g. Firefox), // causing the v-model listener to overwrite values set in @input handlers. const assignListenerOptions: AddEventListenerOptions = { capture: true } // ... addEventListener( el, lazy ? 'change' : 'input', e => { if ((e.target as any).composing) return el[assignKey](castValue(el.value, trim, castToNumber)) }, assignListenerOptions, )Verification
pnpm test-unit runtime-dom— 231 tests passedpnpm test-unit runtime-core(includinguseModel.spec.ts) — 1019 tests passedgit diff --check— clean
Changes are uncommitted in
packages/runtime-dom/src/directives/vModel.tsonly. - v-model (directive) — native
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →