ISSUE DESCRIPTION defineModel on Firefox does not work as expected Vue version 3.5.17…
- User
ISSUE DESCRIPTION
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.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use to restore the file to its original state. You can also reset all changes in the repository using command. Additionally, you can use and to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call ) using or commands. However you don't need to use or before submitting your changes. In fact, only submits currently unstaged changes because it uses to get the changes that need to be submitted.
Assistant
Let me start by understanding the issue. This is about Vue 3's
defineModelnot working correctly on Firefox. The issue seems to be related to how input events are handled on Firefox vs Chrome.Let me explore the repository structure first to understand what we're working with.
Assistant
Let me start by exploring the repository structure.
Assistant
This is the Vue 3 core repository. Let me decode the reproduction link to understand the issue better.
Assistant
Python3 is not available. Let me try with node.
Assistant
Let me decode the playground link with node directly.
Assistant
Now I understand the issue. Let me decode the reproduction:
App.vue:
vue<script setup lang="ts"> import { ref} from 'vue' import Comp from './Comp.vue'; const amount = ref('') </script> <template> <Comp v-model="amount"/> </template>Comp.vue:
vue<script setup lang="ts"> const model = defineModel() function onInput(event: Event) { let modifiedValue = 'a' model.value = modifiedValue } </script> <template> <input v-model="model" @input="onInput" /> </template>The expected behavior: typing anything always shows "a". On Firefox, the typed value "makes it through". Let me look at the relevant source code for v-model directives.
Assistant
Let me look at the vModel directive implementation.
Assistant
Let me look at how
defineModelis implemented and how the mounting order works.Assistant
Now let me look at the
useModelimplementation in runtime-core.Assistant
Let me look at the mounting order in runtime-core to understand when directive hooks and event listeners are attached.
Assistant
Let me look at the mountElement function in detail to understand the order of directive hooks and patchProps.
Assistant
This is the Vue 3 core repository. Let me look at recent commits related to v-model and Firefox issues.
Assistant
Let me look at the existing v-model tests to understand testing patterns and look for the
#8546fix that's mentioned in the code.Assistant
Let me look at how events are patched to understand the listener registration order.
Assistant
Let me search for Firefox-specific issues and look at the changelog for related fixes.
Assistant
Let me look at the git history of the vModel.ts file to understand the #8546 fix and recent changes.
Assistant
That's about checkboxes. Let me look at the #8546 fix specifically - the
activeElementcheck in beforeUpdate.Assistant
Let me look at the original #8546 commit that introduced the
document.activeElement === elcheck.Assistant
Let me write a test to reproduce the issue using the repo's test framework. Let me first check how the existing v-model tests are structured.
Assistant
Let me write a reproduction test using the runtime APIs. Let me check how defineModel/useModel can be used in tests.
Assistant
Now let me create a reproduction test using the runtime-dom (with jsdom) to simulate actual DOM input behavior.
Assistant
I've reproduced the issue. The first keystroke works, but subsequent keystrokes fail (the typed value "makes it through"). Let me look at the #10279 fix in useModel to understand the related pattern.
Assistant
I've reproduced the issue. The first keystroke works (input shows 'a'), but subsequent keystrokes fail (the typed value "makes it through").
Let me analyze the root cause. The key is in
useModel'ssetmethod. Let me trace through what happens:- v-model's input listener (registered first in
created) readsel.value(the typed value) and setsmodel.value = el.value. - The
@inputhandler then setsmodel.value = 'a'.
When the parent has
v-model,localValueis NOT updated byset()— it's only synced viawatchSyncEffectwhen the parent prop changes. On the first keystroke, the parent value changes (''→'a'), triggering a re-render that corrects the DOM. But on subsequent keystrokes, the parent value stays'a'(set to typed value then back to'a'), so no prop change → no re-render → DOM stays out of sync.Let me verify this understanding by adding detailed logging:
- v-model's input listener (registered first in
Assistant
This confirms the issue with realistic typing. After the first 'x' is corrected to 'a', typing 'y' makes it 'ay', then 'ayz'. The DOM gets out of sync because the model stays 'a' (no prop change → no re-render → no DOM correction).
Now let me implement the fix in
useModel. Let me open the file:Assistant
Now let me implement the fix. I'll add a trigger condition for the case where the model is set back to the local value after being set to a different value (by the v-model input listener reading the DOM value), and the parent won't trigger a prop sync:
Assistant
Now let me run my reproduction tests to verify the fix:
Assistant
The fix works. All keystrokes are now corrected to 'a'. Let me clean up my temporary test files and run the existing test suite to make sure I didn't break anything.
Assistant
Let me run the broader test suites that might be affected — the defineModel compiler tests and the runtime-core component tests:
Assistant
All runtime-core tests pass. Let me run the runtime-dom tests:
Assistant
All tests pass. Let me also run the e2e v-model tests and the compiler-dom v-model tests:
Assistant
Let me view the final diff to make sure the change is clean:
Assistant
The diff is clean. Let me verify no temporary test files remain and run the full relevant test suites one more time:
Assistant
Good — only
useModel.tsis modified, and the temp test files inside the repo are removed. Let me run the key test suites once more to confirm everything passes:Assistant
All tests pass. Let me do a final review of the complete modified
setmethod to ensure correctness:Assistant
Let me write a comprehensive edge-case test to verify the fix handles various scenarios correctly without regressions:
Assistant
All edge cases pass. The fix correctly handles the override scenario while preserving normal v-model behavior. Let me clean up the temporary test file:
Assistant
The only change is to
useModel.ts. Let me run the full runtime-core and runtime-dom test suites one final time to confirm everything passes:Assistant
All 1250 tests pass. Let me review the final change one more time before submitting:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.