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 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
Let me understand the issue. It's about
defineModelon Firefox not working as expected. The issue is that when usingdefineModelwith a setter that restricts the value (e.g., only allowing "a"), Firefox doesn't update properly.Let me explore the repository structure first and understand the codebase.
Assistant
This is the Vue 3 core repository. Let me look at the
defineModelimplementation. The issue is related todefineModeland how it handles setting values, specifically on Firefox. Let me look at the relevant code.Assistant
The
defineModelruntime implementation isn't in apiSetupHelpers.ts - it's just a stub there. The actual implementation is in the compiler. Let me look for thedefineModelcompiled output, which involves the runtime helper that creates the model ref. Let me search for it.Assistant
Now I understand the issue. The
defineModelusescustomRefand awatchSyncEffect. Let me look at howv-modelon input works in the runtime-dom.Assistant
Let me decode the reproduction from the issue link to understand the exact code.
Assistant
Let me use raw inflate instead.
Assistant
The base64 has some issue. Let me try writing it to a file and reading properly.
Assistant
Let me look at the
v-modeldirectives in runtime-dom.Assistant
Let me look at the git log and any related tests for
useModel.Assistant
Let me look at the e2e tests for v-model since those run in a real browser, and check for Firefox-related behavior.
Assistant
Let me try to decode the reproduction more carefully, handling potential truncation.
Assistant
The first bytes are 78da which is zlib (default compression). Let me use inflate (not raw) but with finish='mresume' or partial mode to extract partial data.
Assistant
I now have the reproduction. Let me clean it up:
App.vue:
<Comp v-model="amount"/>withconst amount = ref('')Comp.vue:defineModel(),onInputalways setsmodel.value = 'a', template<input @input="onInput" :value="model" />Let me check the changelog for related fixes and look at the scheduler.
Assistant
The reproduction uses
:value="model"(notv-model), so the reset mechanism ispatchDOMPropon re-render. Let me check if I can run a headless browser to reproduce the actual behavior.Assistant
Let me check if puppeteer has Firefox support available.
Assistant
Only Chrome is available in the puppeteer cache. Let me write a test script to reproduce with Chrome first, and check Firefox availability.
Assistant
No Firefox available. Let me build Vue global and reproduce with Chrome to understand the behavior, then reason about the Firefox difference.
Assistant
rollup exists in node_modules but the build script spawns
rollupwhich needs to be on PATH. The.bin/rollupexists. The build scriptscripts/build.jsspawnsrollup- maybe it needs PATH to include node_modules/.bin. Let me try with the right PATH or use npx.Assistant
Now let me create a test HTML page reproducing the issue and test it with Chrome via puppeteer.
Assistant
Let me verify
useModelis exposed on the globalVueobject and create the puppeteer test script.Assistant
Interesting - on Chrome, the first keystroke works ("x"→"a") but the second fails ("ay"). So the Firefox-specific issue is likely in the first keystroke timing. Let me investigate the git history of
useModel.tsto understand the #10279 fix and look for the actual Firefox behavior.Assistant
Let me look at the
componentEmits.tschange in that commit, which may be relevant to the timing.Assistant
Let me check the changelog for defineModel-related fixes to understand the history.
Assistant
Let me test the
v-model+@inputvariant on Chrome to see which matches the issue description.Assistant
I confirmed the
:value+@inputvariant fails on 2nd+ keystrokes on Chrome. Let me test thev-model+@inputvariant, since the reproduction template was garbled and might usev-model.Assistant
Both variants behave identically on Chrome: 1st keystroke works, 2nd+ fail. This confirms the core bug: setting
model.valueto the same value doesn't trigger a re-render to re-sync the DOM.Let me verify my understanding of Vue's
watchcomparison behavior (to ensure my fix won't cause infinite loops with watchers that re-set the same value).Assistant
The watch comparison logic is in the reactivity package. Let me find where the watcher decides whether to call the callback.
Assistant
Let me see the watch logic around line 242-267 to confirm the comparison.
Assistant
Confirmed:
watch(source, cb)only callscbwhenhasChanged(newValue, oldValue)is true (line 248). So triggering on a no-op set re-runs the watcher's getter but does NOT call the callback — no infinite loop for the commonwatch(model, cb)pattern. The render effect re-runs andpatchDOMPropre-syncs the DOM.Now let me look at the exact current code and implement the fix.
Assistant
Now let me implement the fix. I'll modify the early-return to trigger a re-render so the DOM can re-sync, since the bound DOM state (e.g. an
<input>with:value) may be out of sync even though the model value hasn't changed.Assistant
Now let me rebuild Vue global and re-test the reproduction on Chrome.
Assistant
The fix works on Chrome — all keystrokes now reset to "a". Let me also test the case where the parent initializes to "a" (so the first keystroke hits the early-return path) and test the setter-clamp scenario.
Assistant
All scenarios work. Now let me verify I didn't break existing tests. Let me run the useModel spec and related tests.
Assistant
All useModel tests pass. Let me run the defineModel compiler tests and the v-model e2e-related runtime tests as well.
Assistant
All pass. Let me run the broader runtime-core test suite (component, emits, watch) to be safe.
Assistant
All 1019 tests pass. Now let me verify the watcher-loop concern: a
watch(model, cb)that re-sets the same value should NOT cause an infinite loop. Let me write a temporary test.Assistant
The watcher-loop concern is resolved:
watch(model, cb)fired once (comparison skips subsequent same-value sets), no recursive-update warning, input correctly shows "a".Let me run the runtime-dom test suite to be thorough.
Assistant
All pass. Now let me clean up temp files and review the final diff.
Assistant
The diff is clean. However, I referenced an issue number (#13007) that I can't verify. Let me remove the fabricated issue number to avoid misleading documentation.
Assistant
The replace command syntax needs to be on its own. Let me use the proper heredoc format for the
replacespecial command.Assistant
Let me rebuild and re-run the useModel tests to confirm everything is still correct after the comment edit.
Assistant
Let me do one final sanity reproduction with the rebuilt bundle to be 100% sure.
Assistant
All keystrokes correctly keep the input at "a". Let me check git status to ensure I'm only submitting the intended source change (not build artifacts).
Assistant
Only the source file is modified (the dist build is not tracked). Let me do a final review of the complete diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.