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
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
git checkout <file>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
I'll start by exploring the repository structure to understand the codebase and then reproduce the issue.
Assistant
This looks like the Vue.js core repository. Let me explore the packages directory to understand the structure better, and then look for the
defineModelrelated code.Assistant
Let me search for
defineModelto understand where it's implemented:Assistant
Let me look at the Vue playground link to understand what the issue is about. The link shows a reproduction case. Let me decode it and look at the runtime implementation:
Assistant
Let me read the file directly:
Assistant
Now let me decode the playground URL to understand the reproduction case:
Assistant
It looks like the content is compressed (likely with pako/zlib). Let me try with decompression:
Assistant
Let me install pako first:
Assistant
Let me try a different approach - use zlib built into Node.js:
Assistant
Let me try raw inflate:
Assistant
Let me look for existing tests about defineModel to understand the issue better:
Assistant
Let me search for runtime tests related to useModel:
Assistant
Now let me understand the issue better. Based on the issue description, it seems like the problem is related to Firefox and
defineModelnot working properly when trying to filter/validate input. The user says they enter something but only "a" should show, but Firefox doesn't block the other characters.Let me look for issues or PRs related to this:
Assistant
Let me look at the most recent fix:
Assistant
This looks relevant! Let me check the issue #11429 and see what the fix was:
Assistant
This is interesting! This fix adds tracking of
prevSetValueto handle the case where multiple changes happen in the same tick. Now let me understand the current issue better by looking at what could be Firefox-specific.Based on the issue description, let me create a simple test case to understand what might be happening:
Assistant
Let me check if there are any related issues or PRs about Firefox or input handling:
Assistant
Let me look for race condition or input-related issues:
Assistant
Let me try to understand the exact scenario from the playground. Let me look at recent changes to useModel:
Assistant
Let me look at the latest changes more carefully. Let me see what's in commit e0428884b about detecting changes:
Assistant
Now let me look at the most recent fix about kebab-case:
Assistant
Now let me create a test reproduction script based on what I understand about the issue. The issue states that on Firefox, when entering text in a field, it should only show "a" but other characters get through. This suggests a filtering/validation scenario:
Assistant
Now, let me think about the actual issue. Looking at the playground code and the use of
defineModel, the problem is likely that:- User types in an input field
- The setter in defineModel filters the value (e.g., only allows 'a')
- The filtered value is emitted back to parent
- The parent updates the prop
- On Firefox, there's a timing issue where the DOM doesn't get updated synchronously
Let me look at how v-model is handled in the DOM:
Assistant
Let me look at the runtime-dom vModel directive:
Assistant
Now I understand better. The issue is in the
vModelTextdirective'sbeforeUpdatehook. Looking at this code:typescriptbeforeUpdate( el, { value, oldValue, modifiers: { lazy, trim, number } }, vnode, ) { el[assignKey] = getModelAssigner(vnode) // avoid clearing unresolved text. #2302 if ((el as any).composing) return const elValue = (number || el.type === 'number') && !/^0\d/.test(el.value) ? looseToNumber(el.value) : el.value const newValue = value == null ? '' : value if (elValue === newValue) { return } // ... more code el.value = newValue }The problem is that when a user types in an input and the value is filtered by
defineModel's setter, the sequence is:- User types "ab"
Assistant
Now I think I see the issue! The problem is in how
watchSyncEffectis used. Let me look at whatwatchSyncEffectdoes:Assistant
Now I understand! The
watchSyncEffectruns synchronously, which means it should updatelocalValueimmediately when the prop changes. However, the issue is that in Firefox, the timing might be different.Let me look at the set function more carefully:
Assistant
Now I see the issue! When the setter filters the value (e.g., from "ab" to "a"), the code checks:
javascriptAssistant
Let me check what the actual current state of the code is and write a proper test:
Assistant
Looking at the code, I can see the issue. When the setter transforms a value (e.g., from "ab" to "a"), and the emitted value is the same as
localValue, the condition for triggering is:javascriptif ( hasChanged(value, emittedValue) && hasChanged(value, prevSetValue) && !hasChanged(emittedValue, prevEmittedValue) ) { trigger() }The problem is that
trigger()is called butlocalValueis not updated. So when the getter is called after the trigger, it still returns the oldlocalValue.However, thinking about this more carefully - the
watchSyncEffectshould updatelocalValuewhen the prop changes from the parent. The issue might be that in Firefox, the timing is such that the getter is called beforewatchSyncEffecthas a chance to run.Let me look at the test case for #10279 to understand the expected behavior:
Assistant
Assistant
Let me create a test script to better understand the issue and verify my hypothesis:
Assistant
Let me add this test to the existing test file and run it to see if it passes or fails:
Assistant
Let me run this test to see if it passes or fails:
Assistant
Let me try running the tests with pnpm instead:
Assistant
Let me try a different approach - let me just look at what the issue is more carefully by examining the code flow:
Assistant
Let me revert the test changes and focus on implementing the fix:
Assistant
Now let me implement the fix. Based on my analysis, the issue is that when
trigger()is called in the #10279 case,localValuehasn't been updated yet. The fix is to updatelocalValuetoemittedValuebefore callingtrigger():Assistant
Now let me apply the fix:
Assistant
Let me verify the fix was applied correctly:
Assistant
Perfect! The fix has been applied. Now let me create a simple test script to verify the fix works:
Assistant
Excellent! Now let me check if existing tests still pass by examining the test file more carefully:
Assistant
Let me look at this test to make sure my fix doesn't break it:
Assistant
Good! Looking at this test, my fix should not break it. The test expects:
- Initial value: 1
- After input '2': msg=2, compRender=2, shows '2'
- After input '2a': msg=2 (no change), compRender=3 (forced update), shows '2'
- After input '2a' again: compRender still 3 (no update because same value)
With my fix:
- When '2a' is input the first time,
localValueis updated to '2' (emittedValue) before trigger() - When '2a' is input the second time, the condition
hasChanged(value, prevSetValue)will be false (because prevSetValue is already '2a'), so we won't trigger again
This should work correctly!
Now let me check the diff to make sure everything looks good:
Assistant
Perfect! The fix is minimal and targeted. Let me create a comprehensive test to verify the fix works as expected:
Assistant
Now let me verify the fix one more time by looking at the complete context:
Assistant
Perfect! The fix looks good. Let me now write a summary of what the fix does and why it solves the Firefox issue:
Assistant
Now let me verify that my changes look good and check the git status:
Assistant
Let me clean up and verify the final state:
Assistant
. </tool_call>
Assistant
Let me verify the fix is complete and ready for submission:
Assistant
Perfect! Let me review my fix one more time and then submit:
Assistant
Let me verify the complete fix is in place by checking the lines after the condition.
Assistant
Let me verify the fix is correct and then submit it.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.