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
Let me explore the repository structure and understand the issue. The issue is about
defineModelnot working correctly on Firefox. The problem seems to be related to how input events are handled - specifically, when a user types in a field, the value should be blocked/reset to only "a", but on Firefox it doesn't work.Let me first look at the repository structure.
Assistant
This is the Vue 3 core repository. The issue is about
defineModelnot working correctly on Firefox. Let me understand the issue better.The reproduction link shows a component where:
- There's an input field with
v-model(usingdefineModel) - When the user types, the setter only keeps "a" (i.e., it blocks other characters)
- On Chrome this works, but on Firefox it doesn't
The key issue is that when a
v-modelsetter modifies the value (e.g., always returning "a"), the DOM input should be updated to reflect the new value. On Firefox, the DOM doesn't get updated correctly.Let me look at how
defineModelandv-modelwork with input elements, particularly thevModelTextdirective or the model event handling.Let me search for relevant files.
- There's an input field with
Assistant
Let me look at the vModel directive and the useModel helper:
Assistant
Let me look at the
useModelhelper which implementsdefineModel:Assistant
Let me decode the reproduction to understand the exact code:
Assistant
Let me try to decompress the playground code using Node.js:
Assistant
Let me try to install lz-string or use a different approach. Let me look for it in the node_modules.
Assistant
Let me write a Node script to decompress the playground link using lz-string:
Assistant
Let me try a different approach - install lz-string:
Assistant
Let me use the actual encoded string from the issue and try zlib decompression (the
eNqprefix suggests base64-encoded zlib data):Assistant
Now I understand the reproduction. The
Comp.vuehas:<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>So the input has BOTH
v-model="model"AND@input="onInput". TheonInputhandler setsmodel.value = 'a'every time. The issue is about the ORDER of event listeners. Let me investigate the listener registration order.Assistant
Let me check the git log for recent changes to these files:
Assistant
Let me look at the e2e test setup and try to reproduce the issue:
Assistant
Let me check the e2e test utilities and see if I can reproduce with a real browser:
Assistant
Let me check how v-model is compiled and applied — whether it uses
dirsor vnode hooks:Assistant
So the v-model on a native input uses
needRuntime = context.helper(directiveToUse)(V_MODEL_TEXT). This is the directive approach. Let me check how this is applied — is it viawithDirectives(so it's invnode.dirs) or via vnode hooks?Let me look at the codegen for directives.
Assistant
Let me compile a test template to see the actual generated code:
Assistant
No dist. Let me build the compiler or use the source. Let me try building:
Assistant
Let me build the compiler-dom package:
Assistant
Need to build compiler-core too, or build with a bundle that includes everything. Let me build the full vue package which is what the e2e tests use. Actually, let me just build
compiler-coretoo. Or better, let me buildvuewith global format which bundles everything.Actually, let me just build compiler-core first.
Assistant
Let me build the full vue global bundle instead, which is self-contained:
Assistant
Let me look at
invokeDirectiveHookand verify the order ofcreatedvs props patch:Assistant
Let me write a puppeteer test to reproduce the scenario and verify behavior on Chromium:
Assistant
Let me remove the TS syntax from the test:
Assistant
On Chromium, the final value is "a" (correct). The v-model listener fires first, then onInput fires last so "a" wins. Now I need to understand the Firefox difference. Let me search the codebase for any Firefox-related handling:
Assistant
Let me check the changelog for any related fixes and look at the git history around v-model and defineModel:
Assistant
Let me look at the changelog for v3.5.x to find the issue. Let me check the changelogs directory.
Assistant
Let me look at the latest v-model commit to understand the focus check changes:
Assistant
Let me look at the git history of the focus check to understand its intent:
Assistant
Let me find when the
document.activeElement === elcheck was originally added:Assistant
Let me look at the events module to understand how listeners are wrapped:
Assistant
Let me compile the actual SFC template to see the exact generated code. Let me build compiler-sfc:
Assistant
Let me build all the compiler deps needed. Actually, let me use the global build which includes the compiler:
Assistant
Let me use puppeteer to compile the template and inspect the generated render code:
Assistant
The function mode compile returns code that needs Vue global. Let me check what
compilereturns. Maybecodeis undefined because compile in the global build (runtime+compiler) returns a render function directly. Actually,compilereturns{ render, code, ast }I think. But it returned undefined forcode. Let me check - maybe the global build'scompilereturns a compiled function andcodeis not exposed. Let me just getastand inspect, or compile and get the source.Let me try returning the keys.
Assistant
Let me build the compiler-dom as a self-contained esm-browser build:
Assistant
Let me use function mode and add the Vue global:
Assistant
Let me look at the e2e vModel tests for any related scenarios with @input + v-model:
Assistant
Let me look at the useModel spec tests related to force-update and multiple changes:
Assistant
Let me test with multiple keystrokes to see if the bug manifests on the second keystroke:
Assistant
This confirms the bug happens on the second keystroke on Chromium too. The first keystroke works, but subsequent ones don't reset the value. Let me look at the related commit #11430 "correct update with multiple changes in same tick":
Assistant
Let me look at the test added for #11430 to understand the scenario:
Assistant
This confirms the bug happens on the second keystroke on Chromium too — the DOM doesn't reset because the prop doesn't change (final value equals previous), so the component doesn't re-render and
beforeUpdatenever runs. Let me check if I can test with Firefox via playwright:Assistant
Let me try installing playwright to test with Firefox:
Assistant
Let me install the missing system library:
Assistant
Now let me try running the reproduction with Firefox via playwright:
Assistant
On Firefox, the behavior is identical to Chromium: first keystroke works ("a"), but 2nd+ keystrokes fail ("ac", "acd"). So the bug is browser-independent — the DOM doesn't reset on subsequent keystrokes because the prop doesn't change (final value equals previous) so the component doesn't re-render. Let me make a repro using the exact SFC templates via runtime compilation to confirm:
Assistant
Let me run just Firefox with playwright (chromium already confirmed via puppeteer):
Assistant
Confirmed: the bug is browser-independent (same on Firefox and Chromium). The first keystroke works, but subsequent keystrokes don't reset the DOM because the prop doesn't change (final value equals previous) so the component never re-renders and
beforeUpdatenever syncs the DOM. Let me examine the existing force-trigger tests to design a safe fix:Assistant
Let me run the existing useModel tests to understand the current behavior:
Assistant
Let me write a quick script to understand the #10279 test's actual values:
Assistant
Let me add more detailed logging to understand the conversion:
Assistant
Now I understand the number conversion. Let me look at the remaining useModel tests to ensure my fix is safe:
Assistant
Let me look at the "custom setter" test:
Assistant
I now fully understand the root cause. The DOM doesn't reset on subsequent keystrokes because the final model value equals the previous prop value, so the parent re-renders but the child's prop is unchanged → the child doesn't re-render →
beforeUpdatenever syncs the DOM. Let me look at the exact setter code and implement a fix:Assistant
Let me look at the local mutation tests to ensure my fix is safe:
Assistant
Now let me implement the fix. I'll add a force-trigger for the case where the model is set multiple times in the same tick (e.g., v-model's input listener and a user input handler both set the model), and the final emitted value equals the current prop value so the parent won't re-render, but the local input state may be out of sync:
Assistant
There's a duplicate of the
prevSetValue/prevEmittedValuelines. Let me fix:Assistant
The fix looks good. Now let me rebuild the vue global bundle and re-run the reproduction on both Chromium and Firefox to verify:
Assistant
Let me re-run without filtering to see the output:
Assistant
Let me run without grep to see any errors:
Assistant
waitForTimeoutis removed in newer puppeteer. Let me use a setTimeout helper:Assistant
The fix works on both Chromium and Firefox — the value is now always "a" after every keystroke. Now let me run the existing useModel tests to ensure no regressions:
Assistant
All useModel tests pass. Let me run the broader related test suites — defineModel (compiler-sfc), vModel (runtime-dom), and the e2e vModel tests:
Assistant
Now let me run the e2e vModel tests (which use the global build I just rebuilt):
Assistant
The e2e failure is a puppeteer/chromium environment issue (browser launch failed), not related to my change. Let me verify this is pre-existing by checking puppeteer's browser availability:
Assistant
The e2e tests need
--no-sandbox(set whenCIenv is present). Let me run withCI=true:Assistant
The e2e test passes (the earlier failure was just a sandbox env issue). Let me run the broader runtime-core and runtime-dom test suites to confirm no regressions:
Assistant
All pass. Let me run the full e2e suite (with the rebuilt global bundle) to be safe:
Assistant
All e2e tests pass. Let me also run the compiler vModel tests to be thorough:
Assistant
All tests pass. Let me also verify the
defineModelsetoption approach (the documented clamping method) still works correctly with multiple keystrokes in a real browser, plus a scenario where the clamp targets a different value:Assistant
The set-option approach also works on both browsers. Let me check the git status to see what changes will be submitted and clean up any build artifacts:
Assistant
Only
useModel.tsis modified (dist files are gitignored). Let me verify the final diff:Assistant
The fix is clean and minimal. Let me do a final review of the complete modified setter:
Assistant
The fix is complete and verified. Let me make sure no temporary files are left in the repo:
Assistant
The repository is clean — only
useModel.tsis modified. Let me submit the fix.Summary
Issue: When using
defineModelwithv-modelon an<input>plus a clamping@inputhandler (e.g., always setting the model to'a'), the input should only ever show'a'. On the second and subsequent keystrokes, the DOM was not reset to'a'— it kept showing the typed characters (e.g.,ac,acd).Root cause: I reproduced this on both Chromium and Firefox (installing Firefox via Playwright to confirm it is not browser-specific, contrary to the report). On each keystroke two things set the model synchronously:
- The
v-modeldirective's input listener sets the model to the raw DOM value (e.g."ac"), emitting"ac"to the parent. - The user's
@inputhandler sets the model to the clamped value"a", emitting"a"to the parent.
The parent's value ends up at
"a"— the same value it already held. So when the parent re-renders, the child's prop is unchanged ("a" === "a"), the prop-syncwatchSyncEffectdoes not fire, the child component never re-renders, and thevModelTextdirective'sbeforeUpdate(which is responsible for writingel.valueback) never runs. The DOM stays out of sync with the model.Fix (in
packages/runtime-core/src/helpers/useModel.ts): Added a force-trigger in the model setter for the case where the model is set multiple times in the same tick, the intermediate emitted value differs from the final one (hasChanged(emittedValue, prevEmittedValue)), and the final emitted value equals the current prop value (!hasChanged(emittedValue, localValue)) — meaning no parent-driven re-render will occur. Forcing a local re-render letsvModelText.beforeUpdateresyncel.valueto the correct value. This condition is mutually exclusive with the existing#10279force-trigger (they differ on theprevEmittedValueaxis), so no double-triggers occur.Verification:
- Reproduced the bug on Chromium and Firefox (value stuck at
ac/acd). - After the fix, both browsers show
["a","a","a","a"]across keystrokes. - The
defineModelset-option clamping approach still works on both browsers. - All existing tests pass:
useModel.spec(14),defineModel.spec(12), runtime-domvModel.spec(28), compiler vModel specs (39), runtime-core unit (1019), unit-jsdom (378), and the full e2e suite (103).
Checklist
- Reproduced the error — confirmed on both Chromium (puppeteer) and Firefox (Playwright): the DOM fails to reset on the 2nd+ keystroke.
- Confirmed the fix resolves the error — both browsers now show
'a'after every keystroke. - Considered edge cases — first keystroke (no spurious trigger),
set-option clamp (still works), normal v-model (no spurious renders), local-mutation mode (redundant trigger is deduped by the scheduler), clamping to a different value (prop change still drives the update), infinite loops (none — re-render readslocalValueand programmaticel.valuewrites don't fireinput), and wrong renders (none — the trigger always uses the correctlocalValue). The new condition is mutually exclusive with the existing#10279condition. - Ran affected existing tests — all pass (useModel, defineModel, vModel unit/jsdom/e2e, full runtime-core and unit-jsdom suites, full e2e suite).
- The
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 →