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
Let me explore the repository structure first to understand what we're working with.
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 case uses
defineModelwhere the parent sets the model value back to "a" when it changes, but on Firefox the update doesn't "make it through". This is likely related to how the input event handler / v-model is updated.Let me look at the reproduction. The minimal reproduction shows a component with
defineModeland the parent resets the value. On Chrome it works (keeps "a") but on Firefox it doesn't.This is likely related to how the DOM is synced - the issue might be that Vue doesn't re-set the input's value when the model value is reset to the same value it had before, OR there's a timing issue with the input event vs the value being set.
Let me look at the v-model / defineModel implementation in runtime-dom.
Assistant
Let me decode the reproduction link to understand the exact scenario.
Assistant
The encoding might be different. Vue playground uses
lz-string. Let me check - actually the URL#eNq...is likely base64-encoded DEFLATE without the zlib header (raw deflate). But the error says "invalid stored block lengths". Maybe it's actually usingpakoorlz-string. Let me check the Vue playground source.Actually, the Vue playground compresses with
lz-string'scompressToEncodedURIComponent. Let me try that.Assistant
The encoding
eNq...decodes to0x78 0xDAwhich is a zlib header. So it uses zlib (with header), not raw deflate. Let me tryinflateSync.Assistant
Now I understand the reproduction. There's an input with
v-model="model"AND@input="onInput"whereonInputalways setsmodel.value = 'a'. The expected behavior is that the value should always be "a". On Firefox, typed characters "make it through".Let me look at the mount order in runtime-core to understand listener ordering.
Assistant
So in
mountElement, thecreateddirective hook is called BEFOREhostPatchPropfor props (including the@inputlistener). So the v-model input listener is added first, then the @input listener.So on input:
- v-model listener fires first →
el[assignKey](el.value)→ emits update:modelValue with el.value - @input onInput fires →
model.value = 'a'→ emits update:modelValue with 'a'
Both set the parent's
amountref. The final value is 'a' (from the second). But what about the local model value of defineModel?Let me look at defineModel implementation to understand the local value caching.
- v-model listener fires first →
Assistant
Let me look at existing v-model tests to understand expected behavior.
Assistant
Let me search the changelog and git history for related Firefox/v-model issues.
Assistant
Let me look at git blame for the
activeElementblock in vModel.ts to understand its history.Assistant
That's the checkbox change. Let me look at the activeElement block. Let me look at the commit that introduced it.
Assistant
Let me look at the original #8546 commit that introduced the activeElement check.
Assistant
Let me look at the events module to understand how listeners are added.
Assistant
Let me write a test to reproduce the scenario and understand the behavior using jsdom.
Assistant
Let me create a temporary reproduction test that mimics the issue scenario.
Assistant
The test needs
onUpdate:modelValue. Let me rewrite using actualuseModelto mirrordefineModelprecisely.Assistant
Interesting - jsdom reproduces the bug on the 2nd input (
"xb"instead of"a"). Let me investigate the listener firing order and check the exact flow. Let me add detailed logging.Assistant
Let me check the e2e setup to potentially test in a real browser.
Assistant
Let me check if there's a prebuilt dist and try a real-browser (Chromium via puppeteer) test.
Assistant
No dist yet. Let me build the vue.global.js. Actually, let me check the build scripts. But building might be slow. Let me try a simpler approach: use vite to bundle a quick test, or use the
@vitejs/plugin-vue...Actually, the simplest: build the global bundle. Let me check the build command.
Actually, maybe I can avoid building by using the runtime-dom directly in node with jsdom, but I already did that and it bugs on 2nd keystroke. The question is whether real Chrome differs.
Let me build the global bundle and run a puppeteer test. Let me check package.json scripts.
Assistant
The build script spawns
rollupdirectly, not via npx/node_modules/.bin. Let me check the PATH or use a different approach. Let me add node_modules/.bin to PATH.Assistant
Now let me write a puppeteer test to reproduce the scenario in real Chromium.
Assistant
I need plain JS (no TS syntax in evaluate). Let me rewrite.
Assistant
Let me put the script in the repo root so it can resolve puppeteer.
Assistant
Real Chromium with simulated input events also shows the bug on the 2nd keystroke. But my simulation may not match real keyboard input. Let me use puppeteer's real keyboard typing to faithfully reproduce actual browser behavior.
Assistant
Real keyboard typing in Chromium keeps the value as
"a"(works!), but simulateddispatchEventbugs. So the difference is in how real keyboard events vs simulated events are dispatched. Let me instrument to understand the real keyboard flow.Assistant
Very revealing! At the 2nd keystroke,
model.value(before onInput set) is already"ab", meaning the local value was updated. Let me instrument when props sync happens to understand the synchronous flow.Assistant
The prop is syncing synchronously in real Chrome (
PROP CHANGED to "x"appears beforeONINPUT). This is surprising. Let me check if jsdom behaves the same way with identical logging, to find the difference.Assistant
The jsdom test I just ran had NO
vModelTextdirective (onlyonInput), so it's not comparable. The key finding from real Chrome: the v-model listener fires first, then@input, with synchronous prop sync. Let me redo the jsdom test WITH thevModelTextdirective to match the real scenario.Assistant
Now I see the critical difference. In real Chrome, the prop syncs synchronously between the v-model listener and
@input. In jsdom (manual dispatch), the prop syncs asynchronously (after the event). Let me log the parent/child render timing in real Chrome to understand the synchronous prop sync mechanism.Assistant
Let me use a render function for the parent to log render timing, keeping Child2 as a template.
Assistant
The CDP
console.logordering may be unreliable. Let me record the execution sequence into a synchronous global array in the page, then read it, to get reliable ordering.Assistant
The
recruns during initial mount when input doesn't exist yet. Let me guard it.Assistant
Now I have reliable synchronous ordering. The parent re-renders synchronously between the v-model listener and
@inputin real Chrome. Let me examine the scheduler to understand whenflushJobsruns synchronously.Assistant
The scheduler uses a microtask (
resolvedPromise.then(flushJobs)). The empirical data shows the parent renders between the twoinputlisteners in real Chrome keyboard input. Let me check whereflushPreFlushCbsis called synchronously.Assistant
The scheduler uses microtasks, so the parent rendering between the two listeners means a microtask ran between them in real Chrome keyboard input. This is surprising for same-dispatch listeners. Let me check the compiled output of
<input v-model="model" @input="onInput" />and probe the event dispatch.Assistant
The vue.global.js build I made (
node scripts/build.js vue -f global -d) is the runtime+compiler build (theglobalformat includes the compiler when not-f global-runtime). Let me check ifwindow.Vue.compileexists. Actually the dev global build ofvueincludes the compiler. Let me just use it.Wait, my script tried to add a non-existent compiler-sfc.global.js first and failed. Let me fix to only add vue.global.js.
Assistant
The build I made was runtime-only. Let me build the full Vue (with compiler) global build to inspect compilation.
Assistant
Let me compile the template using the compiler via a vitest test (which can import TS source).
Assistant
Now I see the compiled output confirms
onUpdate:modelValue: $event => (model.value = $event)and a separateonInput. Let me directly probe whether a microtask checkpoint exists between the v-model listener and@inputwithin a single input event dispatch.Assistant
This is the key finding! In real Chrome, a microtask runs between the v-model listener and
@input(thePARENT-renderandPROP->xappear betweenAMOUNT->xandONINPUT). This synchronous prop sync updateslocalValuesoonInput's set proceeds and the DOM gets resynced. In Firefox/jsdom, the prop sync is async (after the event), so the net model change is zero and the DOM isn't resynced.Let me study the defineModel set logic history to find the right fix point.
Assistant
Let me look at the test added for #11430 and other defineModel tests to understand the constraints.
Assistant
Now I understand the root cause. Let me verify whether this is specific to
defineModelor also affects regularv-model+@input. Let me test the regular v-model case.Assistant
This is the key insight! With regular v-model, the bug does NOT occur (all
"a"), but with defineModel it does. The difference: regular v-model's refsetdirectly triggers the render effect, so the component re-renders andbeforeUpdateresyncs the DOM. ButdefineModel'sset(when v-model is present) deliberately does NOT trigger — it relies on the parent's prop sync. When the parent's net change is zero (value set then reverted in the same tick), no prop sync happens, no re-render, DOM stays desynced.Let me re-read the exact
useModelset code to implement the fix.Assistant
Let me see the rest of the set function.
Assistant
Now I understand the fix. When v-model is present,
defineModel'ssetrelies on the parent's prop sync to updatelocalValueand trigger a re-render. But when the parent's value ends up unchanged (set then reverted in the same tick — which happens when bothv-modeland a user@inputlistener update the model), no prop sync occurs, no re-render, and the DOM stays out of sync. The fix: force a re-render in this case so the v-model directive can resync the DOM.Let me implement the fix.
Assistant
Now let me implement the fix. I'll refactor the v-model check into a
hasVModelvariable and add anelse ifbranch.Let me edit lines 67-83.
Assistant
The fix looks good. Now let me rebuild the global bundle and re-run the jsdom repro test to verify.
Assistant
The fix works in jsdom (all
"a"). Let me rebuild the global bundle and verify in real Chrome (both manual dispatch and real keyboard) to ensure I didn't break Chrome.Assistant
Excellent! The fix works in jsdom and real Chrome (both manual dispatch and real keyboard). Now let me ensure I didn't break existing tests — run the
useModelandvModeltest suites.Assistant
All 42 tests pass. Let me run the broader runtime-core and runtime-dom suites to ensure nothing else breaks.
Assistant
All 1251 tests pass. Let me check git status and clean up my temporary files.
Assistant
The dist build is gitignored (not showing). Let me clean up all my temporary files.
Assistant
Only the
useModel.tschange remains. Let me run the e2e vModel test (real browser) as a final verification. First build the dist needed for e2e.Assistant
The e2e browser failed to launch (environment config issue, not my change). Let me check the e2eUtils launch config.
Assistant
The e2e launch doesn't specify
executablePath. Let me set the env to use the available google-chrome.Assistant
The e2e vModel test passes in a real browser. Let me clean up the dist build and review the final diff.
Assistant
The diff is clean and minimal. Let me run the TypeScript type-check to ensure no type errors were introduced.
Assistant
No type errors. Let me confirm there are no tsc errors at all (checking full output count).
Assistant
No type errors (exit code 0). Let me do a final review of the complete modified
setfunction.Assistant
The fix is complete and correct. Let me do a final verification of git status and run the affected test suites once more to confirm everything is green.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.