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
I'll start by exploring the repository structure and understanding the issue with
defineModelon Firefox. - Assistant
Let me decode the reproduction and find the defineModel implementation.
- Assistant
Python3 is not available. Let me try node.
- Assistant
Let me try gunzipSync instead.
- Assistant
Trying inflate with different zlib options.
- Assistant
The issue is about forcing DOM updates when
defineModelassigns the same value. Let me look at the related code. - Assistant
rg is not available, use grep.
- Assistant
Let me look at useModel which is the runtime implementation of defineModel.
- Assistant
Let me read the useModel implementation and also related v-model code for inputs.
- Assistant
Let me see the rest of the file and also look at related issues or v-model with inputs.
- Assistant
Let me read the full vModel directive implementation.
- Assistant
Continue reading beforeUpdate
- Assistant
Let me check event ordering and any related bugs/fixes in the changelog.
- Assistant
There's a notable fix: "force local update when setter results in same emitted value" for #10279. That's related.
- Assistant
Let me check the order of patching props vs directives.
- Assistant
Let me look at the mountElement function more carefully around line 666-750 to see order of props vs directive created.
- Assistant
I need to understand how prop updates flow when emit happens during an input event.
- Assistant
Vue 3 flushes component updates synchronously inside native event handlers. Let me verify that.
- Assistant
Let me look at how emit continues to call the handler and also scheduler flush in update mechanism. Also specifically NATIVE event flushing.
- Assistant
Let me search for related issues and tests about this v-model/defineModel pattern.
- Assistant
There's a test specifically for "force local update when setter formats value to the same value" and "should not force local update if set to the same value". Let me read those tests carefully.
- Assistant
Continue reading the test
- Assistant
Let me look for known issues or git history related to Firefox and microtasks between event listeners.
- Assistant
There's a commit specifically about workflow updates with multiple changes in the same tick - that sounds related.
- Assistant
That's about multiple sets in same tick when value ends up same as something... Let me also look at f1bb0aef0 and de174e1aa. I think the issue is likely in the
setfunction logic, specifically around the condition that decides whether to emit an update or not. The race condition you're describing sounds like it could be related to how the emitted value is compared against the previous state, especially when Firefox might be updating the DOM at a slightly different timing than Chrome.Let me break down the key parts:
-
The early return condition:
!hasChanged(emittedValue, localValue) && !(prevSetValue !== EMPTY_OBJ && hasChanged(value, prevSetValue))- This seems to be the main guard that prevents unnecessary updates.
- In your Firefox case, it might be evaluating differently due to how
hasChangedworks with the values.
-
The #10279 special case: This is checking if we need to force a trigger because the local value might be out of sync.
-
- Assistant
Let me look at the base vModel transform in compiler-core and how onUpdate:modelValue is generated for elements.
- Assistant
Let me read the full DOM transform.
- Assistant
Continue.
- Assistant
Let me search for related issues on GitHub versions and look at recent changes related to v-model.
- Assistant
There's a commit about preventing unnecessary DOM updates from v-model that might have introduced the regression.
- Assistant
Let me check git history and any pending changes, and try to write a reproduction test.
- Assistant
Let me write a temporary test to reproduce the useModel-filtering bug pattern.
- Assistant
Let me write a temporary test that reproduces the issue and run it.
- Assistant
I'll put the test in packages/runtime-dom/tests temporarily.
- Assistant
The test timed out. Let me try a different approach.
- Assistant
- Assistant
I've confirmed the bug and root cause. Implementing the force-trigger fix when the emitted value matches
localValueso the DOM re-syncs. - Assistant
There's a subtle operator precedence issue кре with
!!rawProps && (a) && (b)- the original used!(rawProps && a && b)which is slightly different. - Assistant
Repro is fixed. Now run existing useModel tests and vModel tests.
- Assistant
All useModelفيها tests pass.ие Let me also flies run vModel tests and clean up the temporary file.
- Assistant
All tests pass. Running a broader suite on runtime-core helper tests to be sure.
- Assistant
All 1019 tests pass. Let me review the final diff before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.