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
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.
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 usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /core, current file: none) bash-$
- Assistant
I'll start by exploring the repository to understand the structure and locate the relevant code for
defineModel. Let's first see what we're dealing with. - Assistant
Let me explore the repository structure to understand the Vue.js codebase and find the relevant code for
defineModel. - Assistant
Let me understand the issue. The issue is about
defineModelnot working as expected on Firefox. Let me look at the reproduction link to understand what the user is trying to do. They mention that when usingdefineModel, they want to only allow "a" as input, but it doesn't work on Firefox.Let me look at the
defineModelimplementation in the Vue codebase. - Assistant
Let me look at the runtime
useModelimplementation sincedefineModelcompiles to use that: - Assistant
Let me examine the useModel implementation.
- Assistant
Now let me look at the defineModel spec test to understand how it's supposed to work:
- Assistant
Now let me understand the issue better. Let me look at how
v-modelon native inputs works and how the value gets set back: - Assistant
Let me decode the playground URL to understand the reproduction:
- Assistant
Let me try python instead.
- Assistant
Let me try with node.js
- Assistant
Now I understand the reproduction. The issue is:
- A child component uses
defineModel()and binds to an<input>withv-model="model" - There's also an
@inputhandler that forcesmodel.value = 'a' - On Firefox, this doesn't work - the input value isn't being reset properly
Let me look at the vModel directive implementation:
- A child component uses
- Assistant
Now let me understand the flow better. Let me look at how events are mounted in the runtime:
- Assistant
Let me look at the runtime-core's mount element logic to understand ordering:
- Assistant
Let me look at the renderer to understand how event listeners are attached and the order they fire.
- Assistant
Let me look at the mountElement function:
- Assistant
Now I understand the issue better. Let me trace through the code flow to understand the Firefox-specific problem. Let me look at how events are handled:
- Assistant
Now let me understand the full picture. Let me look at recent git history related to
useModelandvModelText: - Assistant
Let me look at the issue more carefully. Let me look at recent issues related to Firefox:
- Assistant
Let me understand the reproduction better. Let me look at how the compiler handles
v-modelcombined with@input: - Assistant
Let me look at the vModel transform to understand how the compiler generates the event handler for v-model on inputs.
- Assistant
Now let me understand the core issue. Let me look at the
beforeUpdatehook ofvModelTextmore closely, specifically the part where it decides whether to updateel.value: - Assistant
Let me look at the
#10279fix and understand the force local update logic more carefully: - Assistant
Now let me understand the issue better. The problem is with
defineModelon Firefox. Let me decode the playground link to understand the reproduction case. - Assistant
Let me look at the issue more carefully. Let me re-read the reproduction code:
The reproduction from the playground:
App.vuehas aref('')namedamountand passes it asv-modeltoCompComp.vuehasdefineModel()and binds it to<input v-model="model" @input="onInput" />onInputsetsmodel.value = 'a'(always forces "a")
The problem: When you type in the input in Firefox, the
inputevent fires. Thev-modeldirective on the input element readsel.valueand calls the model setter. Then the@inputhandler also fires and setsmodel.value = 'a'. But the input shows what you typed instead of "a".Let me think about the ordering of event handlers:
- The
vModelTextdirective adds aninputevent listener in thecreatedhook - The
@input="onInput"also adds an event listener viapatchEvent
In
mountElement, directivecreatedhooks are called BEFORE props are patched. So:vModelText.createdruns → adds input event listener (listener A)- Props are patched →
@inputis added as event listener (listener B)
When the
inputevent fires, both listeners run. The order should be:- Listener A (vModelText): reads
el.valueand callsel[assignKey](...)which triggersonUpdate:modelValue - Listener B (@input): calls
onInput()which setsmodel.value = 'a'
But wait, there's something subtle here. The
v-modelon a native input compiles to a directive. But@inputis a regular event handler. However, the v-model directive also adds its own event listener for theinputevent.Let me look at how the v-model directive's input handler works more carefully.
The v-model directive adds:
addEventListener(el, 'input', e => { if ((e.target as any).composing) return el[assignKey](castValue(el.value, trim, castToNumber)) })And the
@inputhandler is:function onInput(event: Event) { let modifiedValue = 'a' model.value = modifiedValue }Both are on the
inputevent. The v-model listener is added first (increatedhook), then the @input listener is added (in prop patching).So when the input event fires:
- v-model handler fires first:
el[assignKey](el.value)→ this emitsupdate:modelValuewith the current el.value - @input handler fires second:
model.value = 'a'
Now, the key question is: in step 1,
el[assignKey]is thegetModelAssigner(vnode)which getsonUpdate:modelValuefrom the vnode props. This is the function that the parent passes to update the model. In the case ofv-model="model"on a native input, this callsmodel.value = el.value.Then in step 2,
model.value = 'a'overrides it.But wait - there's a race condition here. When
model.valueis set twice in the same synchronous execution:- First
model.value = el.value(e.g., "ab") → this triggersuseModel.set("ab") - Then
model.value = 'a'→ this triggersuseModel.set("a")
In
useModel.set, the first call:emittedValue = "ab",localValue = "a"(current value)hasChanged("ab", "a")= true → doesn't return early- Emits
update:modelValuewith "ab" to parent - Sets
prevSetValue = "ab",prevEmittedValue = "ab"
Then the second call:
emittedValue = "a",localValue = "a"(still the same, hasn't been updated by prop sync yet)hasChanged("a", "a")= false- Also checks
prevSetValue !== EMPTY_OBJ && hasChanged("a", "ab")→ true - So
!hasChanged(emittedValue, localValue) && !(prevSetValue !== EMPTY_OBJ && hasChanged(value, prevSetValue)) - =
true && !(true)=true && false= false → DOESN'T return early - Emits
update:modelValuewith "a" to parent
So the parent will eventually get value "a" and re-render. But here's the key: the v-model directive's
beforeUpdatehook is what updates the DOM input value.In
beforeUpdate:beforeUpdate(el, { value, oldValue, ... }, vnode) { el[assignKey] = getModelAssigner(vnode) if ((el as any).composing) return const elValue = ... // el.value const newValue = value == null ? '' : value if (elValue === newValue) { return // ← IMPORTANT: skips update if el.value already matches } ... el.value = newValue }The problem is: after the model is set to "a", when
beforeUpdateruns,el.valuemight still be "ab" (the user typed value), andnewValueis "a", soelValue !== newValueand it should update. So that should work...Wait, let me reconsider. The issue says "Firefox does not work as expected". Maybe the problem is with the event handler ordering. In Firefox,
@inputmight fire BEFORE the v-model directive's input handler?Actually, looking at the code again: in
mountElement, directivecreatedhooks run BEFORE props are patched. So the v-model directive's event listener is added first viaaddEventListener. Then the @input handler is added. But wait - how is @input added?Looking at
patchEvent, it creates an invoker and adds it viaaddEventListener. So both are nativeaddEventListenercalls. The order of event listener execution in the DOM is the order they were added.So v-model's listener fires first, then @input fires second. That seems correct.
Hmm, but let me think about this differently. What if the problem is about how
beforeUpdatein vModelText works?After both event handlers run:
model.valuehas been set to "a" (via the second handler)- The parent receives
update:modelValuewith "a" - The parent re-renders, passing
modelValue = "a"back to Comp - Comp's
defineModel()ref sees the new prop value - The v-model directive's
beforeUpdateruns withvalue = "a"
But what's
el.valueat this point? It's the user-typed value, e.g., "ab". SoelValue !== newValue, andel.value = "a"is set.Wait, but there's also the v-model directive's
createdhook's event listener. That listener fires FIRST and readsel.value. Then @input fires and setsmodel.value = 'a'.But in the first handler,
el[assignKey](castValue(el.value, trim, castToNumber))is called. TheassignKeyis thegetModelAssigner(vnode)which is theonUpdate:modelValuefrom the parent. Forv-model="model"on an input insideComp, this ismodel.value = el.value.Actually wait, I'm confused about the nesting. Let me re-think:
- The parent
Apphasv-model="amount"onComp. This meansCompreceivesmodelValueprop andonUpdate:modelValueevent. - Inside
Comp, there's<input v-model="model" @input="onInput" />. This is the native input v-model.
For the native input
v-model="model", the compiler transforms this to a directive that:- Creates the input element with
modelValue: model.valueandonUpdate:modelValuethat updatesmodel.value - But wait, for native elements, v-model is handled differently. The directive
vModelTexthandles it.
Actually, let me look at this more carefully. For a native
<input v-model="model">, the template compiler:- Removes
modelValuefrom the props - Adds
vModelTextdirective with binding value =model.value - Adds
onUpdate:modelValueevent handler that setsmodel.value
So the vNode for the input has:
onUpdate:modelValue:(val) => { model.value = val }(from v-model compilation)onInput:onInputfunction (from @input)
Both of these are on the same vnode. The vModelText directive's
createdhook:- Gets
el[assignKey] = getModelAssigner(vnode)→ this isonUpdate:modelValuefrom the vnode props - Adds an input event listener that calls
el[assignKey](el.value)
Then props are patched: 3.
onInputis added viapatchEventSo when the input event fires:
- v-model's listener fires:
el[assignKey]("ab")→ this callsmodel.value = "ab" - @input listener fires:
onInput()→model.value = "a"
Both are synchronous. After both handlers run,
model.valueis "a" (the second assignment wins).Now, in the
useModelsetter:- First call with "ab": emits "ab" to parent
- Second call with "a": emits "a" to parent
Both emissions happen synchronously. The parent's re-render is batched. Eventually the parent re-renders with
amount = "a", passesmodelValue = "a"to Comp, and the vModelText directive'sbeforeUpdateruns.At this point,
el.valueis still "ab" (the browser's input value), andnewValueis "a". Soel.value = "a"is set.But here's where the Firefox issue might come in. In Firefox, there might be a race condition where the browser is still processing the input event and the cursor position, and setting
el.valueduringbeforeUpdatemight not work correctly because the browser is in the middle of updating the input.Actually, wait. Let me re-read the issue description more carefully. The issue says:
Enter anything in the field. It should be blocked and only show "a", but it wont on firefox.
So the issue is that when you type in the input, it doesn't get blocked to "a". The input shows what you typed.
Let me think about this differently. Maybe the problem is that in Firefox, the
beforeUpdatehook returns early becauseelValue === newValue.Wait, that would only happen if
el.valueis already "a" whenbeforeUpdateruns. But after typing "b",el.valueshould be "ab" or "b", not "a".Hmm, unless the model setter sets the value back to "a" synchronously, and then the
beforeUpdateruns withel.valuealready being "a"...Actually, I think I need to look at this from a different angle. Let me look at how
useModelinteracts with thevModelTextdirective'sbeforeUpdate.Actually wait - I think I understand the issue now! The problem is with the
el[assignKey]in the vModelText directive. TheassignKeyis a Symbol stored on the element. It's set in thecreatedhook:el[assignKey] = getModelAssigner(vnode)And also updated in
beforeUpdate:el[assignKey] = getModelAssigner(vnode)But wait, that's the assigner for the native input's v-model, not for the component's defineModel.
Let me think about this again...
Actually, I think the issue is more subtle. Let me trace through the exact sequence of events in Firefox:
-
User types "b" in the input (currently showing "a")
-
The native
inputevent fires -
First handler (vModelText directive): calls
el[assignKey]("b")→ this triggersonUpdate:modelValuewhich callsmodel.value = "b" -
In
useModel.set("b"):emittedValue = "b",localValue = "a"→hasChanged= true- Emits
update:modelValue("b")to parent prevSetValue = "b",prevEmittedValue = "b"
-
Second handler (@input): calls
onInput(event)→model.value = "a" -
In
useModel.set("a"):emittedValue = "a",localValue = "a"→hasChanged= false- But
prevSetValue = "b",hasChanged("a", "b")= true - So the condition:
!hasChanged("a", "a") && !("b" !== EMPTY_OBJ && hasChanged("a", "b"))=true && false= false - Doesn't return early
- Emits
update:modelValue("a")to parent - #10279 check:
hasChanged("a", "a")= false → doesn't trigger local update prevSetValue = "a",prevEmittedValue = "a"
-
Now the parent has received two updates: first "b", then "a". The last one is "a".
-
Parent re-renders with
amount = "a", passesmodelValue = "a"to Comp -
useModel'swatchSyncEffectruns:propValue = "a",localValue = "a"→ no change → no trigger -
But Comp still re-renders because parent re-rendered
-
vModelText's
beforeUpdateruns:value = "a",el.value = "b"(still shows what user typed?)- Wait,
el.valueat this point... hmm.
- Wait,
Actually, step 9 is interesting. The
watchSyncEffectdoesn't trigger becauselocalValueis already "a". But the parent did re-render, so the child re-renders anyway. The vModelTextbeforeUpdateruns withvalue = "a".Now, what's
el.valueat this point? In Chrome, it might be "b" (what the user typed before it was set to "a" by the useModel). But wait, in the event handler sequence, the v-model directive's handler readsel.valueto get "b", and then later the @input handler forcesmodel.value = "a". Butel.valueis still "b" because nothing has changed the DOM yet.So
beforeUpdateshould seeel.value = "b"andnewValue = "a", and setel.value = "a". This should work.But wait - maybe in Firefox, the
beforeUpdateruns butel.valueis already "a" somehow? Or maybe thebeforeUpdatedoesn't run at all because the parent didn't actually trigger a re-render?Hmm, let me reconsider. After step 6, the parent emitted "a". But the parent's current value is already "" (the initial value). The parent updates
amount = "a"and re-renders. This triggers a re-render of the child withmodelValue = "a".But wait, the
useModel'swatchSyncEffectseespropValue = "a"andlocalValue = "a"(because localValue was never updated since both emits happened in the same tick). SohasChangedis false,trigger()is not called. But the component still re-renders because the parent re-rendered... right?Actually, I need to think about this more carefully. The
useModelreturns acustomRef. ThecustomRefis used in the template. When the parent re-renders, the child's render function is called (because props changed). Inside the render function,model.valueis accessed, which calls thegetof the customRef, which returnslocalValue(which is "a"). The v-model directive binding value ismodel.valuewhich is "a".So
vModelText.beforeUpdateis called withvalue = "a". Andel.valueis still "b" (or whatever the user typed). So it should update.OK, I'm going in circles. Let me look at the issue from a completely different perspective.
Maybe the issue is NOT about the model value at all. Maybe it's about the Firefox browser specifically not updating the
el.valueproperly when it's set duringbeforeUpdatewhile the input is focused.Actually, let me look at the
beforeUpdatecode again:const rootNode = el.getRootNode() if ( (rootNode instanceof Document || rootNode instanceof ShadowRoot) && rootNode.activeElement === el && el.type !== 'range' ) { // #8546 if (lazy && value === oldValue) { return } if (trim && el.value.trim() === newValue) { return } } el.value = newValueThis code does NOT return early for a focused input (unless it's lazy or trim). So it should always set
el.value = newValue.Wait, but what about the check at the top:
if (elValue === newValue) { return }What if
el.valueis already "a" at this point? That could happen if:- The v-model directive's input handler ran and set
model.value = "b" - Then
@inputhandler ran and setmodel.value = "a" - In
useModel.set("a"), the local update was triggered (#10279 logic) - This caused an immediate re-render/update of the v-model directive
beforeUpdateran synchronously withvalue = "a", andel.valuewas set to "a"- Then later, when the parent re-renders,
beforeUpdateruns again withvalue = "a", andel.valueis already "a"
Hmm, but step 3-5 wouldn't happen synchronously. The
trigger()call in #10279 only triggers a re-render, which is batched.OK, let me take a completely different approach. Let me look at the issue from the Firefox perspective. What's different about Firefox's input handling?
One key difference: Firefox fires the
inputevent AFTER the DOM has been updated, while Chrome fires it BEFORE. Wait, no, that's not right. The spec says theinputevent fires after the DOM is updated.Actually, I think the key difference might be about how Firefox handles the caret/selection position. In Firefox, when you programmatically set
el.value, the caret position might be preserved or reset differently than in Chrome. But that shouldn't cause the value to be different.Let me try yet another approach. Let me look at recent issues and PRs related to Firefox and v-model.Let me look at the specific behavior: when
v-modeland@inputare both on the same<input>, the order of event listeners matters. Let me look at how Vue compiles and handles this: - Assistant
Now let me look at what the actual issue is. Let me think about the reproduction more carefully. Let me look at the playground code decoded:
Comp.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>When user types in the input, both
v-modelhandler and@inputhandler fire. Let me trace through the exact flow: - Assistant
Let me now understand the exact flow in the reproduction by examining how
vModelTexthandles value updates and howuseModelinteracts with it. - Assistant
Now I have a clear picture of the bug. Let me trace through the flow step by step.
The reproduction has:
Comp.vuewithdefineModel()and<input v-model="model" @input="onInput" />whereonInputforcesmodel.value = 'a'App.vuepassesv-modeltoComp
When the user types in the input (e.g., typing "b" after "a" is already shown):
- The
v-modeldirective's input handler fires first (registered increatedhook) → callsonUpdate:modelValue("ab")→model.value = "ab"→useModel.set("ab")→ emits "ab" to parent,prevSetValue = "ab",prevEmittedValue = "ab" - The
@inputhandler fires → callsmodel.value = "a"→useModel.set("a")
In
useModel.set("a"):emittedValue = "a",localValue = "a"(from prop sync)hasChanged("a", "a")= false → early return condition checks:!hasChanged(emittedValue, localValue)= trueprevSetValue = "ab",hasChanged("a", "ab")= true- So
!(true && true)= false - Overall:
true && false= false → does NOT return early → emits "a" to parent
After both emits, parent has
amount = "a". Parent re-renders withmodelValue = "a". But the child'smodelValuewas already "a", soshouldUpdateComponentreturns false, and the child doesn't re-render.el.valuestays as "ab"!Wait, but the user says it works in Chrome. Let me check the
#10279fix more carefully and look at the specific condition that should trigger a local update... - Assistant
Now I understand the issue. Let me trace through the exact flow more carefully:
When user types in the input, TWO event handlers fire:
vModelText's handler (registered increatedhook) - callsel[assignKey](el.value)→ triggersuseModel.set("ab")@inputhandler - callsmodel.value = 'a'→ triggersuseModel.set("a")
After both set calls:
- Parent received "ab" then "a", ending at "a" (same as before)
localValueis "a" (unchanged)- Child doesn't re-render because props haven't changed from parent's perspective
el.valuestays "ab" in the DOM
The fix needs to trigger a local update when the emitted value equals the local value (so parent won't trigger prop sync) but differs from the previous emission. Let me create a test to verify:
- Assistant
Now let me look at
shouldUpdateComponentto understand when child components are re-rendered: - Assistant
Let me look at the
shouldUpdateComponentfunction: - Assistant
Let me understand the issue better. The problem is:
- User types in input with
v-model="model"and@input="onInput"whereonInputalways setsmodel.value = 'a' - In Firefox, the input shows what was typed instead of being forced to "a"
Let me trace through the execution carefully:
- User types "b" (input was showing "a")
- The
inputevent fires - Two handlers fire:
- vModelText handler (registered in
createdhook): readsel.value= "ab", callsel[assignKey]("ab")which triggersonUpdate:modelValue("ab")- this goes to parent's handler - @input handler: calls
model.value = 'a'which triggersuseModel.set('a')
- vModelText handler (registered in
But wait, the
onUpdate:modelValuehandler on the input element is NOTuseModel.set. The v-model on a native input element uses thevModelTextdirective, which reads the value fromel.valueand calls theonUpdate:modelValuehandler.For a child component with
defineModel(), the compiled template would be something like:h('input', { modelValue: model.value, 'onUpdate:modelValue': $event => (model.value = $event), onInput: onInput }, null, PatchFlags.NEED_HYDRATION)Wait, actually for native elements,
v-modelcompiles to a directive. Let me look at how the compiler handles it.Actually, for native
<input v-model="model">, the compiler produces:- A
vModelTextdirective with valuemodel.value - An
onUpdate:modelValueevent handler that setsmodel.value = $event
When
vModelTextfires its input handler, it callsel[assignKey](el.value)whereassignKeyisonUpdate:modelValuefrom the vnode props.So the flow is:
- User types "b" → el.value = "ab"
- input event fires
- vModelText handler fires: calls
onUpdate:modelValue("ab")which is($event) => (model.value = $event)→model.value = "ab"→ triggersuseModel.set("ab") - @input handler fires:
model.value = 'a'→ triggersuseModel.set('a')
In
useModel.set("ab"):- emittedValue = "ab"
- localValue = "a" (from previous)
- hasChanged("ab", "a") = true → continues
- Emits
update:modelValuewith "ab" to parent - prevSetValue = "ab", prevEmittedValue = "ab"
In
useModel.set("a"):- emittedValue = "a"- localValue = "a" (unchanged since prop hasn't updated)
- hasChanged("a", "a") = false
- prevSetValue = "ab", hasChanged("a", "ab") = true
- !hasChanged(emittedValue, localValue) && !(prevSetValue !== EMPTY_OBJ && hasChanged(value, prevSetValue))
- = true && !(true && true) = true && false = false
- So it does NOT return early
- Emits
update:modelValuewith "a" to parent
Now parent gets two emits: "ab" then "a". The parent's
amountgoes from "a" → "ab" → "a". Net result: still "a".Then parent re-renders with amount = "a", passes modelValue = "a" to child. The
watchSyncEffectcheckshasChanged(localValue, propValue)=hasChanged("a", "a")= false, so no trigger.But wait, the
el.valueis still "ab" because the browser set it. ThevModelText.beforeUpdatewould need to run to setel.value = "a".So the question is: does the component re-render? The
shouldUpdateComponentwould need to return true.Let me look at
shouldUpdateComponent: - User types in input with
- Assistant
Now I understand the issue. Let me trace through the exact flow in the reproduction:
- User types "b" in input showing "a" →
el.value = "ab" inputevent fires- vModelText handler fires first (registered in
createdhook): callsel[assignKey]("ab")→ triggersuseModel.set("ab")→ emits "ab" to parent →amount = "ab" - @input handler fires:
model.value = 'a'→ triggersuseModel.set("a")→ emits "a" to parent →amount = "a"
After both,
amount = "a"(same as before). Parent re-renders, butshouldUpdateComponentreturns false becausemodelValueis "a" both before and after. The child doesn't re-render.el.valuestays "ab" in the DOM.The key issue: the
useModelsetfunction doesn't trigger a local update when the emitted value is the same as the local value but was different from the previously emitted value (meaning the parent's state changed and changed back within the same tick).Let me look at the early return logic and the #10279 fix:
- User types "b" in input showing "a" →
- Assistant
Now I have a clear understanding. Let me first run the existing tests to make sure they pass:
- Assistant
Good, all 14 existing tests pass. Now let me implement the fix. The issue is in the
useModelsetfunction. After emitting, when the emitted value equals the local value (so the parent won't trigger a prop sync) but differs from the previously emitted value (meaning the parent's state changed and changed back within the same tick), we need to force a local trigger so the child re-renders and the DOM gets synced. - Assistant
Now let me implement the fix. I need to add a condition after the #10279 check:
- Assistant
Now let me add the fix:
- Assistant
Let me use the
editcommand instead: - Assistant
Now I need to add the fix. Let me use the
editcommand to add the new condition after the #10279 check. - Assistant
Now let me run the existing tests to make sure they still pass:
- Assistant
All 14 existing tests pass. Let me also run the defineModel compile tests:
- Assistant
Good. Now let me write a test script that reproduces the exact issue from the bug report and verify the fix:
- Assistant
Let me write a proper test as a standalone script to validate the fix works:
- Assistant
Let me write a proper test case and run it using vitest:
- Assistant
The test file needs to be inside the packages directory. Let me create it in the right place:
- Assistant
Let me fix the import path:
- Assistant
The test passes functionally but the assertion format differs. Let me fix the test:
- Assistant
The test passes with the fix. Let me verify that without the fix, this test would fail:
- Assistant
Without the fix, the test fails:
compRenderwas only called 2 times instead of 3, confirming the bug. Let me restore the fix: - Assistant
Good, the fix is restored. Let me now run ALL existing tests related to useModel and defineModel:
- Assistant
All 26 tests pass. Let me also run a broader set of tests to make sure nothing else breaks:
- Assistant
All 1020 tests pass across 45 test files. Let me clean up the temporary test file and also run the compiler-sfc tests:
- Assistant
All tests pass. Let me now review the final state of my fix:
- Assistant
The fix is clean and minimal. Let me now verify the fix one final time by checking the exact file:
- Assistant
The fix is correct and clean. Let me now verify no temporary files are left and run the complete test suite one final time:
- Assistant
Good, only the
useModel.tsfile is modified. Let me run the final comprehensive test:
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →