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 then investigate the issue related to
defineModelon Firefox.Assistant
This is the Vue.js core repository. Let me investigate the
defineModelandv-modelimplementation. The issue is aboutv-model(used bydefineModel) not updating correctly on Firefox, likely related to how the model value is set back to the input.Assistant
Let me decode the reproduction case to understand the exact scenario:
Assistant
Let me try a different approach to decode the URL hash. The Vue playground uses
#then base64-encoded (URL-safe) then LZ-compressed. Let me try with node.Assistant
Now I understand the scenario. The component has both
v-model="model"(which adds its own internal input listener) AND@input="onInput". TheonInputhandler setsmodel.value = 'a', overriding whatever was typed. The order in which the two input listeners fire matters. Let me look at how the directive hooks and event listeners are set up during mount:Assistant
Let me look at the events module to understand how
addEventListenerworks in the v-model directive versus how@inputis patched:Assistant
Let me look at the
defineModelimplementation to understand the local model sync:Assistant
Let me find the runtime implementation of the model ref (the
_defineModelruntime helper):Assistant
Let me look at how
v-modelis compiled for native elements, to understand the listener setup:Assistant
Let me compile the actual component to see the output and understand the directive + listener setup:
Assistant
Let me find the correct path for the compiler-sfc dist.
Assistant
No dist. I'll need to either build the compiler-sfc or write the test using the source via a different approach. Let me check if there's a way to import from the source directly. Actually, let me use vitest which has the aliases set up. Or let me check the vitest config.
Actually, let me just write a vitest test temporarily. But the instructions say not to add tests to the repo. I can create a temp test file outside the test directories, or use a scratch script.
Actually, let me try building compiler-sfc, or use the @vue/compiler-sfc via the source with tsx/esbuild. Let me check if vitest is available and can run a single scratch file.
Assistant
OK so for
v-model, thetransformModeldirective transform is called. It returns{ props: [modelValue, onUpdate:modelValue] }WITHOUTneedRuntime. Sov-modelon a NATIVE element compiles to just propsmodelValue+onUpdate:modelValue??Wait, that can't be right because then how does the input event get handled? Let me re-check. Actually wait, doesn't return . Let me re-read:
Assistant
The DOM compiler overrides
transformModel. Let me read it:Assistant
Let me search for related code and comments about the activeElement / focused-element guard and the issue number referenced:
Assistant
Let me look at the git history of the vModel.ts file to understand the context of the
activeElementguard:Assistant
Let me look at the v-model test file to understand existing test scenarios, especially around the focused-element behavior:
Assistant
Let me look at the test around line 378 which tests the focused-element behavior, and understand the activeElement guard:
Assistant
Let me check the CHANGELOG for any Firefox-related fixes and search for relevant patterns:
Assistant
Let me write a reproduction script using the actual Vue runtime to understand the current behavior. First, let me check how to run a quick test with the source:
Assistant
Let me create a temporary reproduction test to observe the current behavior in jsdom:
Assistant
In jsdom, the result is correct ("a"). The bug is Firefox-specific. Let me reproduce with the actual
useModel(whichdefineModelcompiles to) to make sure the early-return logic inuseModelisn't a factor:Assistant
Interesting! In jsdom, the bug IS reproducing: after the first keystroke, the DOM shows "ab", "abc" instead of "a". Let me add instrumentation to understand the re-render/beforeUpdate behavior:
Assistant
Now I can see the key insight: after the first keystroke, the parent re-renders (
parentRender=3,4) but the child does NOT (childRender=2stays) because the model value ends up the same ("a"), sohasPropsChangedreturns false, the child never re-renders, andbeforeUpdateis never called to reset the DOM.Let me now test the listener-order hypothesis directly by manually controlling the order of the two input listeners (v-model internal vs user
@input):Assistant
Now this is very revealing! With a plain ref the result is correct ("a"), but with useModel (defineModel) the DOM accumulates ("ab"). The difference is the parent-child component setup. Let me look at
hasPropsChangedto understand why the child doesn't re-render:Assistant
The key finding:
hasPropsChangedignores emit-listener props (onUpdate:modelValue), so when the model value ends up unchanged ("a"→"a"), the child component never re-renders, sobeforeUpdatenever runs to reset the DOM. This is the core bug. Let me look at theuseModelhistory and the #10279 fix for context:Assistant
Let me look at the subsequent fixes (#11162, #11430) to understand the evolution of the early-return logic:
Assistant
Now I understand the evolution of the early-return logic (#10279, #11162, #11430). Let me look at
patchElementto confirm thatbeforeUpdateruns even when the directive value is unchanged (just the DOM is out of sync):Assistant
Assistant
Assistant
Let me stop over-analyzing and just implement and test. Let me write the fix and verify with the reproduction test.
Assistant
Now I understand the code and tests well. Let me look at the remaining useModel tests to be thorough:
Assistant
Now let me implement the fix. Let me carefully modify the
setmethod inuseModel.ts:Assistant
Now let me make the edit. I'll update the trigger comment and condition to handle the non-setter case:
Assistant
Now let me run my reproduction test to see if the fix works:
Assistant
That's the simplified test. Let me restore the full useModel reproduction test:
Assistant
The fix works — the DOM is now correctly reset to "a" after each keystroke. Let me also test some edge cases. First, let me test the case where the user handler sets the model to a DIFFERENT value than the prop (not the same), to make sure I'm not over-triggering:
Assistant
I found a bug in my fix. The "uppercase" case (model set to a different value than the prop) fails — input shows "" instead of "B". Let me trace this:
Uppercase case: prop=''. User types 'b' (el.value='b').
- v-model set('b'): emitted='b', local=''. Not early return. emit 'b'. #10279: no. My new cond: hasChanged('b', EMPTY_OBJ)=true, hasChanged('b', undefined)=true, !hasChanged('b','')=false → no trigger. prevSetValue='b', prevEmitted='b'.
- onInput set('B'): emitted='B', local=''.
- early return? !hasChanged('B','')=false → no.
- emit 'B'.
- #10279: hasChanged('B','B')=false → no.
- My new cond: hasChanged('B', prevSetValue='b')=true, hasChanged('B', prevEmitted='b')=true, !hasChanged('B', local='')=false (hasChanged('B','')=true → !true=false) → NO trigger.
- prevSetValue='B', prevEmitted='B'.
- Final: parent '' → 'b' → 'B'. Re-renders. Child prop='B'. watchSyncEffect: local '' → 'B'. trigger. Child re-renders. beforeUpdate: elValue='b', newValue='B' → el.value='B'. DOM='B'.
Wait, so the parent DOES change ('' → 'B'), so the child should re-render and reset to 'B'. But the test shows input=''. So beforeUpdate didn't run, or it set el.value to ''.
Assistant
Assistant
Interesting! With my fix, amount='' (the parent value didn't update to 'B'!), and beforeUpdate never ran. So onInput's emit of 'B' didn't reach the parent (amount stayed '').
Why? Because onInput set('B') did an EARLY RETURN (didn't emit)! Let me check the early return condition:
jsif (!hasChanged(emittedValue, localValue) && !(prevSetValue !== EMPTY_OBJ && hasChanged(value, prevSetValue))) returnAssistant
All edge cases pass with my fix. Let me verify these same edge cases WITHOUT my fix to confirm the baseline (some should fail, showing the fix is needed):
Assistant
The comparison is clear:
- WITHOUT fix:
fixed-a casefails ('ayz' instead of 'a') — the issue bug. - WITH fix: all 4 pass.
The uppercase and same-as-prop cases pass both with and without the fix (they're not affected by the listener-order issue because the parent value changes). My fix only affects the case where the emitted value equals the local value (parent won't re-render) — exactly the issue scenario.
Now let me run the existing useModel and vModel test suites to make sure I didn't break anything:
- WITHOUT fix:
Assistant
Both existing test suites pass. Now let me clean up my temporary test file and run the broader test suites:
Assistant
Now let me run the broader runtime-core and runtime-dom test suites to make sure nothing else breaks:
Assistant
The only failure is a flaky performance test (
should not lead to exponential perf cost with deeply chained computed) — a timing-based test unrelated to my change. Let me verify it's pre-existing by running it again:Assistant
It passes on re-run — confirming it's a flaky timing test, not related to my change. Now let me run the runtime-dom (jsdom) tests:
Assistant
All runtime-dom/jsdom tests pass. Now let me also run the e2e tests related to v-model to be safe:
Assistant
The e2e tests fail because puppeteer can't launch the browser (running as root without
--no-sandbox). This is an environment limitation, not related to my change. The e2e tests are all skipped (not failed assertions), just browser-launch failures.Let me look at the e2e vModel test to see if there's something I should be aware of (a test that might cover this scenario):
Assistant
That e2e test is about checkboxes and isn't directly related to my change. The browser launch fails due to sandbox restrictions in this environment, which is unrelated.
Now let me review my final change and verify the logic once more by reviewing the diff:
Assistant
Now let me reconsider whether this issue number is correct. Let me search the issue tracker references. The issue title is "defineModel on Firefox does not work as expected". Let me check the actual issue number — I used #13221 as a placeholder. Let me search if there's a way to find the actual issue number, but since I can't access the internet, let me use a more generic comment that references the behavior rather than a specific number I'm guessing at.
Actually, let me reconsider. The reproduction is from Vue 3.5.17. Let me check the changelog/issues for the actual issue number. Let me search the repo for any reference:
Assistant
Let me update the comment to be descriptive rather than guessing an issue number:
Assistant
Now let me re-run the tests one more time to confirm everything passes after the comment change:
Assistant
Now let me do a final reproduction test to confirm the fix works, then remove the temp test:
Assistant
The fix works. Let me clean up the temporary test file:
Assistant
Now let me run the type check to make sure my change doesn't break the TypeScript build:
Assistant
TypeScript check passes with no errors. Let me also run the SFC compiler tests related to defineModel and the full runtime-core test suite once more to be thorough:
Assistant
All 3181 tests pass (the flaky perf test passed this time too). Let me also verify the final diff one more time:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.