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
I'll start by exploring the repository structure to understand the codebase and locate relevant files for the issue about
defineModelnot working as expected on Firefox. Let's first see what's in the root directory. - Assistant
Let me explore the repository to understand the structure and find where
defineModelis implemented. - Assistant
Let me understand the issue. The user is reporting that
defineModelon Firefox doesn't work as expected. Let me look at the reproduction link to understand what the code is doing.From the reproduction URL, I can see this is about Vue's
defineModelmacro. Let me look at the runtime implementation to understand how it works.Let me first look at the runtime implementation of
defineModeland understand the issue better. - Assistant
Let me look at the useModel helper, which is the runtime implementation of defineModel.
- Assistant
Now let me understand the issue. The problem is about defineModel on Firefox. The reproduction link seems to show a case where a v-model is used and there's a modifier or set/get that should restrict the value to "a" only, but it doesn't work on Firefox.
Let me think about what could cause Firefox-specific behavior. In Vue, when using v-model on an input, the update process involves:
- The user types in the input
- An
inputevent fires - Vue updates the valueThe issue seems to be about a race condition between the input event and the value update. Let me look at the v-model implementation on input elements.
Let me check how v-model is handled in the runtime-dom package.
- Assistant
Let me look at the vModel directive implementation.
- Assistant
Let me understand the reproduction better by decoding the URL hash:
- Assistant
Let me try to decode the base64 from the URL. The hash in the URL is a base64-encoded JSON object.
- Assistant
Let me try with python or node.
- Assistant
Now I understand the reproduction. Let me analyze it:
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>App.vue:
vue<script setup> const amount = ref('') </script> <template> <Comp v-model="amount"/> </template>So the issue is: when using
defineModelwithv-modelon an<input>and also having an@inputhandler that forces the value to "a", on Firefox the value doesn't get forced to "a". Let me investigate the flow and see what's happening. - Assistant
Let me trace through the flow more carefully. Let me look at how defineModel compiles and understand the event handling flow:
- Assistant
Now I need to understand the interaction between the
v-modeldirective's input handler and the@inputevent handler. Let me trace through the flow: - Assistant
Let me look at the useModel implementation more carefully, since it's the core of defineModel:
- Assistant
Let me understand the reproduction better. The issue is: when using
defineModel()andv-modelon an<input>with an@inputhandler that setsmodel.value = 'a', it should always show "a", but on Firefox it doesn't.Let me trace through the flow:
- User types "b" → input shows "ab"
inputevent fires - two handlers fire: v-model directive's handler, then@input="onInput"- v-model handler reads
el.value= "ab", callsmodel.value = "ab"which emits to parent onInputhandler setsmodel.value = "a"which emits to parent- Parent updates, re-renders child,
vModelText.beforeUpdateshould setel.value = "a"
Let me look at recent commits and issues related to this:
- Assistant
Let me look at the
vModelText.beforeUpdatemore carefully and trace through the event flow: - Assistant
Let me look at how the input event handlers are registered and in what order:
- Assistant
Let me look at how element mounting works to understand the order of event handler registration:
- Assistant
Let me look at the order in mountElement:
- Line 693:
invokeDirectiveHook(vnode, null, parentComponent, 'created')- directivecreatedhooks are called - This is where the v-model directive adds its
inputevent listener
But where are the regular event handlers (like
@input) added? Let me look at patchProps. - Line 693:
- Assistant
Now let me look at the update flow to understand when the
beforeUpdatedirective hook is called: - Assistant
Now I need to understand the core issue. Let me look at what happens when both
v-modeland@inputare on the same input element. Let me look at how events are dispatched in the v-model handler: - Assistant
Let me look at how the component update works and when
beforeUpdatedirective hook runs: - Assistant
Let me focus on the key issue. Let me look at the useModel setter and the flow of events when typing in the input:
- Assistant
Let me trace through the exact flow to understand the issue better. Let me look at how event listeners are registered on the
<input>element: - Assistant
Let me look at the shouldUpdateComponent function and how Vue decides to re-render child components:
- Assistant
Let me look at the key issue more carefully. The problem is likely related to the order of event handlers and the useModel update mechanism. Let me trace through the scenario step by step:
- Assistant
Now I need to deeply understand the issue. Let me trace through the exact scenario:
- User has
<input v-model="model" @input="onInput" />wheremodelis fromdefineModel()andonInputalways setsmodel.value = 'a' - User types a character
The key issue: When the input event fires, two handlers fire in order:
- The v-model directive handler reads
el.valueand calls the model setter - The
@inputhandler setsmodel.value = 'a'
Let me look at the event listener registration order and the
useModelsetter logic more carefully: - User has
- Assistant
Now I understand the issue deeply. Let me trace through the exact scenario:
- User types 'b' into input that shows 'a' →
el.value = 'ab' inputevent fires, two handlers run in order:- v-model directive handler (registered in
vModelText.created): readsel.value = 'ab', callsmodel.value = 'ab'→ emits'ab'to parent @inputhandler: callsonInput()→model.value = 'a'→ emits'a'to parent
- v-model directive handler (registered in
- After both, parent's
amountis'a'again (same as before) localValueis still'a'(never changed since parent has v-model and prop didn't update yet)- Parent re-renders with
amount = 'a', passesmodelValue = 'a'to child watchSyncEffectseespropValue = 'a',localValue = 'a'→hasChangedis false → no trigger!- Child doesn't re-render,
el.valuestays as'ab'→ BUG!
The fix needs to ensure
trigger()is called when the emitted value matches the local value but the value was changed by an intermediate handler. Let me implement the fix: - User types 'b' into input that shows 'a' →
- Assistant
Let me look at the rest of the file and then create a test to reproduce the issue:
- Assistant
Now let me create a test to reproduce the issue first:
- Assistant
Let me look at the existing tests for useModel to understand how to write a test for this:
- Assistant
Now let me write a test to reproduce the issue:
- Assistant
Let me look at the existing tests to understand the test patterns:
- Assistant
Let me understand the problem better by looking at how the v-model directive handler interacts with the
@inputhandler. Let me trace through the flow more carefully. - Assistant
Now I understand the full flow. Let me trace through the exact issue:
-
When user types 'b' in the input (currently showing 'a'):
- Browser sets
el.value = 'ab' inputevent fires- v-model directive handler fires FIRST: reads
el.value = 'ab', calls setter → emits'ab'to parent @inputhandler fires SECOND: callsmodel.value = 'a'→ emits'a'to parent
- Browser sets
-
After both calls, parent's value went from
'a'→'ab'→'a'(net: no change) -
localValuewas never updated (parent has v-model, local update skipped) -
Parent re-renders with
modelValue = 'a',watchSyncEffectsees no change → notrigger() -
Child doesn't re-render,
el.valuestays as'ab'
The fix needs to ensure
trigger()is called when the setter's emitted value matcheslocalValuebut there was an intermediate different set value. Let me implement the fix: -
- Assistant
Now let me implement the fix:
- Assistant
I see there's a duplicate comment. Let me fix that:
- Assistant
I see there are duplicated lines. Let me rewrite the file properly:
- Assistant
Now let me carefully apply the fix:
- Assistant
Now let me apply the fix:
- Assistant
Good, the fix looks correct. Now let me run the existing tests to make sure nothing is broken:
- Assistant
All 14 existing tests pass. Now let me write a test to verify the fix works for this specific scenario. Let me first check the existing test patterns:
- Assistant
Let me look at the "force local update when setter formats value to the same value" test (the #10279 fix test) as a pattern:
- Assistant
Now let me write a test that reproduces the exact issue from the bug report:
- Assistant
Now let me add a proper test to the existing test file:
- Assistant
Let me look at the end of the test file to add a new test:
- Assistant
Now let me add a test for the specific scenario from the issue. Let me add it before the closing
}): - Assistant
Let me verify the test file ends correctly and check the imports:
- Assistant
Good, all necessary imports are already there. Let me run the tests:
- Assistant
The first failure seems to be a pre-existing test issue. Let me check:
- Assistant
All 14 original tests pass. The failure must be in my test. Let me fix the test:
- Assistant
Let me check the custom setter test that's failing:
- Assistant
Let me see the full error output:
- Assistant
Let me check if the "custom setter" test was passing before:
- Assistant
Hmm, the custom setter test fails with my change. Let me check the diff to make sure I didn't break anything:
- Assistant
Let me understand the custom setter test better. Let me add some debugging:
- Assistant
Let me check what's happening with the failing test. Let me add a quick debug test:
- Assistant
I don't see the console output. Let me check:
- Assistant
Now I see! The third call is emitting 'true' because
msg.valueisnulland the setter returnstrue. Let me check if this was already happening before my change: - Assistant
Interesting! The third call emits 'true' even WITHOUT my change. But the test passes. Let me run the actual test file:
- Assistant
Wait, the test file was already modified. Let me check:
- Assistant
Let me verify the original tests pass cleanly:
- Assistant
Wait,
git stashsays "No local changes to save" - that means the stash already popped. Let me check the current state. - Assistant
Hmm, it seems like the useModel.ts file was reverted. Let me check.
- Assistant
It seems the stash already popped. Let me re-apply my changes:
- Assistant
My changes got lost. Let me re-apply them and also remove the debug test file:
- Assistant
My changes to useModel.ts got reverted but the test changes remain. Let me re-apply the fix:
- Assistant
Wait, I realize the issue. Let me check the "custom setter" test more carefully. Let me revert everything and run it cleanly:
- Assistant
Let me check how the test renderer handles scheduling - this might be key to understanding the behavior:
- Assistant
Let me add inline debug to understand what's happening in the custom setter test:
- Assistant
Let me trace through the "custom setter" test more carefully. I need to understand what
localValueis at each point.The key is:watchSyncEffectwithflush: 'sync'runs synchronously when its tracked dependency changes. But what triggers it?The
watchSyncEffectwatchesprops[camelizedName]. In Vue's reactivity system, whenpropschanges (the reactive proxy), the effect fires. Butpropsis a shallowReactive object managed by the component instance. It's updated when the parent re-renders and passes new props.But wait - in the test, after
changeChildMsg(true)is called the first time:model.value = true→ useModel setter emitsupdate:msgwithtrue- Parent's
onUpdate:msghandler runs:
- Assistant
Let me revert and take a different approach. Let me understand the custom setter test by running it with logging.
- Assistant
Let me add actual logging to the source and run the custom setter test:
- Assistant
Let me trace through the "custom setter" test carefully. The key is what happens with the
localValueand the early return condition. Let me check the behavior without any changes: - Assistant
Let me understand the custom setter test behavior. Let me revert and add logging directly to the test:
- Assistant
It seems like
git checkout .didn't actually change anything. Let me check the current state of the files. - Assistant
OK, the working tree is clean. Let me take a fresh approach - I need to understand the "custom setter" test properly before applying my fix. Let me add a console.log directly in the test:
- Assistant
Let me revert and write a minimal reproduction test directly:
- Assistant
The debug test shows that the third call DOES emit
true, changingmsg.valuetotrue. But the original test passes without my changes! Let me check the original test more carefully: - Assistant
The original test passes but my debug test doesn't - something is fundamentally different. Let me add logging directly to useModel to understand what happens:
- Assistant
Only 2 setter calls logged! The third
changeChildMsg(true)never enters the setter. Let me check: - Assistant
Only 2 setter calls! The third
changeChildMsg(true)doesn't enter the setter. This means something prevents it. Let me check ifchangeChildMsgis even called 3 times: - Assistant
Only 2 setter calls happen! The third
changeChildMsg(true)never enters the setter. This is very interesting. Let me add logging at the VERY start of the setter to confirm: - Assistant
Very interesting - only 2 setter calls! The third
changeChildMsg(true)doesn't trigger the setter at all. This means the ref system detected no change. Let me restore and think about this differently. - Assistant
Now I need to understand why the third setter call doesn't happen. Let me look at how
@vue/runtime-testhandles scheduling: - Assistant
No results found. Let me search more broadly.
- Assistant
Let me understand the scheduler behavior better - the key is why the 3rd setter call never fires:
- Assistant
Let me check how
customRefworks - maybe it does some value checking: - Assistant
Let me look at the customRef implementation to understand if there's a check for value changes before calling the setter.
- Assistant
Let me look at the CustomRefImpl class:
- Assistant
Let me look at the CustomRefImpl class:
- Assistant
Interesting! The customRef setter always runs - no value check. But only 2 setter calls happen. Let me add logging at the VERY start of the setter:
- Assistant
Still only 2 setter calls. The third
changeChildMsg(true)doesn't trigger the setter. This means the ref system is preventing it. Let me check what happens - maybe the parent re-renders between calls, which causeslocalValueto update, and then the early return condition catches the third call. But the log says the setter isn't even entered the third time!Wait - maybe the parent re-rendered synchronously between calls 2 and 3 due to the
watchSyncEffect. Ifmsg.valuechanged, the parent's effect might re-render synchronously, and thewatchSyncEffectupdateslocalValue. Then after re-render,childMsgbecomes a different ref...No,
childMsgis captured by closure. Let me check ifmsg.valuepropagation works differently. Let me look atflushJobs: - Assistant
I need to understand why the 3rd setter call doesn't happen. The
customRefalways calls_set, so maybe between calls 2 and 3, the parent re-renders andlocalValuechanges, making the early return kick in. Let me check by adding logging before the early return: - Assistant
Only 2 setter calls! The 3rd
changeChildMsg(true)doesn't even trigger the setter. This is crucial. Let me check if the parent re-renders synchronously between calls - maybeflush: 'sync'on watchSyncEffect triggers an immediate re-render: - Assistant
The setter is only called twice! The 3rd call doesn't even enter the setter. But customRef's
set value()always calls_set(). Unless between calls 2 and 3, the parent's render flushes synchronously and creates a new child component. Let me check if the parent re-renders synchronously: - Assistant
Now I see the setter IS called 3 times! The trace shows all 3 calls. But the earlier test with the
-tfilter only showed 2 - maybe that was a different test file issue.Now the key insight: the 3rd call does enter the setter and emits
true, changingmsg.valuetotrue. But the original test expectsnull! So how does the original test pass?The answer must be: between the 2nd and 3rd calls, the parent re-renders (synchronously via watchSyncEffect flush: 'sync'), updating the child's
localValue. This causes the early return in the 3rd setter call!Let me check by running the original test:
- Assistant
OK, the original test passes. Now let me understand why my fix breaks it. The key insight from the trace is that the setter IS called 3 times, but after call 3,
msg.value = true. Yet the original test expectsnulland passes!This means between call 2 and call 3, the parent re-renders, updating
localValue. Let me verify by checking ifwatchSyncEffectwithflush: 'sync'causes synchronous re-render: - Assistant
OK, the 3rd call DOES enter the setter and emits
true. But the original test expectsmsg.valueto benulland passes. This means between call 2 and call 3, the parent re-renders (viawatchSyncEffectflush:sync) andlocalValueis updated, which makes the early return condition true in call 3. Let me verify: - Assistant
- Assistant
Now let me run the custom setter test with my fix:
- Assistant
Wait, it passes now! Let me run all tests:
- Assistant
All 14 tests pass with my fix! The earlier failure was due to the test file being modified. Now let me add the test for the Firefox issue:
- Assistant
Now let me check the file to make sure the test was added correctly:
- Assistant
Wait, the closing
})for the describe block is missing. Let me check: - Assistant
Good, the closing
})is still there. Let me check: - Assistant
The test was appended after the closing
})of the describe block. I need to fix this - the new test needs to be inside the describe block. Let me check the structure: - Assistant
I need to move the test inside the describe block. Let me fix this:
- Assistant
Now let me run all the tests:
- Assistant
The empty value serialization is
<input value></input>not<input value=></input>. Let me fix this: - Assistant
Let me fix the test assertion for empty value serialization:
- Assistant
The issue is that the initial value is an empty string '' and it renders as
<input value></input>not<input value=></input>. Let me fix this assertion. - Assistant
The runtime-test serializes values with quotes. Let me fix the assertions:
- Assistant
All 15 tests pass! Now let me run a broader set of tests to make sure nothing else is broken:
- Assistant
All 1020 tests pass. Let me also run the compiler-sfc defineModel tests and the runtime-dom vModel tests:
- Assistant
All tests pass. Let me verify the changes by looking at the diff:
- Assistant
The changes look clean. Let me clean up temporary files and run the broader test suite:
- Assistant
Now let me also run the full Vue test suite (excluding slow ones) to make sure nothing else breaks:
- Assistant
All tests pass. Let me now submit the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.