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
Good, jsdom-based tests using vitest. Let's create a temporary test to reproduce the scenario.
Assistant
Need to use
requirealternative - import useModel directly instead of require.Assistant
Now let's run the repro test and the full useModel test suite plus vModel directive tests.
Assistant
Repro test passes now. Let's run the full useModel test suite and other related tests.
Assistant
Now run the tests again.
Assistant
All tests pass now. Let's run the broader runtime-core and runtime-dom test suites to make sure nothing else broke.
Assistant
All tests pass. Let's also run the compiler-sfc / full test suite for related areas (defineModel compiler-sfc tests) to be thorough, then clean up.
Assistant
Now let's remove the temporary repro test file and run the full test suite once more as a final sanity check.
Assistant
This diff looks clean and minimal. Now let's re-verify the full useModel + runtime-dom + runtime-core suites once more (without the repro file) and also check type-checking passes.
Assistant
All pass. Let's also run type-check to make sure TS compiles cleanly for this file.
Assistant
Type-checking passes cleanly. Let's do a final review of the complete modified file for correctness and clean formatting.
Assistant
This looks good. Let's run lint/format check to ensure style conformance.
Assistant
Both ESLint and Prettier pass cleanly. Now let's do a final full test run of the whole repo (or at least a broad relevant subset) to be extra sure.
Assistant
Confirmed - both failures are pre-existing environment issues (no sandbox for puppeteer as root, and a flaky perf-timing test), unrelated to my change. This confirms my fix doesn't introduce any regressions.
Assistant
Summary
Root cause analysis: The issue reproduction (defineModel +
v-model+ an additional native@inputhandler that resets the model value) revealed a real, browser-independent race condition inuseModel()'s underlyingcustomRef.When a v-model-bound model ref is set multiple times within the same tick (e.g., once by the internal
vModelTextdirective listener with the raw typed value, and again by a user's own@inputhandler that overrides it back to a fixed value), and the final emitted value happens to equal the value the local model already had before this tick started, thewatchSyncEffectthat syncsprops[camelizedName]back intolocalValuenever detects a change (since the prop round-trips back to the same value). Because of this,trigger()is never called, the component's render effect never re-runs, and thereforevModelText'sbeforeUpdateDOM-correction logic (which forcesel.valueback in sync) never executes — leaving the native<input>element's DOM value out of sync with the actual model value. This differs across browsers only in how visibly/likely this race manifests (timing/dispatch quirks), but the underlying logic bug is deterministic and reproducible in jsdom as well.Fix: In
packages/runtime-core/src/helpers/useModel.ts, extended the existing "force local update" logic (previously only handling the#10279setter-conversion edge case) to also cover the no-setter case: when a value is set multiple times in the same tick and the final emitted value equals the pre-ticklocalValue(so the prop-sync watcher won't fire), we now force atrigger()so the component's render effect always re-runs and reconciles the DOM/local rendering with the actual model state.Verification:
- Wrote a temporary reproduction test simulating the exact scenario from the issue (v-model + overriding
@inputhandler) — confirmed it failed before the fix (input.valuestuck at'ab'instead of'a') and passes after. - Ran the full
useModeltest suite,runtime-dom/runtime-coretest suites, andcompiler-sfcdefineModeltests — all pass. - Ran
tsc --noEmit, ESLint, and Prettier — all clean. - Ran the full repo test suite; only pre-existing environment-related failures remain (puppeteer e2e tests fail due to no sandbox as root, and one flaky perf-timing test), confirmed identical on a clean checkout without my changes.
- Removed the temporary reproduction test file before submitting.
- Wrote a temporary reproduction test simulating the exact scenario from the issue (v-model + overriding
Assistant
Checklist review
-
If an error was reported in the issue description, I have successfully reproduced it. Yes — I decoded the SFC playground reproduction, rebuilt it as a jsdom-based vitest test simulating
defineModel()+v-model+ an overriding@inputhandler, and confirmed thatinput.valueincorrectly stayed at'ab'instead of resetting to'a', matching the reported browser symptom. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes — after patching
useModel.tsto force a localtrigger()when a model value is set multiple times in the same tick and round-trips back to its pre-tick value, the reproduction test passes (input.valuecorrectly becomes'a'). -
I have thought about edge cases and made sure my fix handles them as well. Yes — I carefully preserved the existing
#10279setter-conversion forced-update behavior (verified via existing testforce local update when setter formats value to the same value), verified the new condition doesn't fire on the very firstset()call (prevSetValue !== EMPTY_OBJguard), and confirmed kebab-case / non-syncing-parent scenarios still avoid unnecessary re-renders. -
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Yes — ran
useModel.spec.ts, all ofruntime-coreandruntime-domunit tests,compiler-sfcdefineModeltests,tsc --noEmit, ESLint, and Prettier — all pass. Ran the full repo test suite; the only failures are pre-existing environment issues (puppeteer sandbox restrictions under root, and one flaky performance-timing test), verified to fail identically without my change applied.
-
Assistant
The fix has been implemented and verified. Let me do one final confirmation that everything is in order before submitting.
Assistant
Good, the change is clean and only touches the relevant file. No leftover temporary test files. Let's submit.
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 →
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 →