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
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 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
I’ll first inspect the repository structure and decode the playground reproduction so I can identify whether this is a compiler-generated
defineModelissue or a runtime DOM synchronization issue. Then I’ll locate relevant tests and reproduce the browser-dependent event sequence as closely as the existing test infrastructure permits. - Assistant
The repository is Vue core at a newer 3.5 patch, and dependencies are present. Python is unavailable, so I’ll use Node’s built-in zlib to decode the reproduction payload, then search for the generated model helper and DOM
v-modelupdate logic. - Assistant
The reproduction has nested synchronization: the input directive first assigns the typed value to the component model, then the user
@inputhandler immediately assigns"a". Since the parent receives both emissions synchronously but component props are patched asynchronously,useModel’s duplicate-emission suppression is a likely source. I’ll inspect that helper and its unit tests, along with event listener ordering. - Assistant
I found a substantial dedicated
useModeltest suite. I’ll read the implementation and the tests around rapid consecutive assignments and transformed setters to understand its intended invariants before changing behavior. - Assistant
The implementation already contains logic intended to allow a second assignment back to the current prop value (
prevSetValuecheck), so the straightforward synchronous sequence should emit both the typed text and"a". The remaining browser-dependent path is DOM reconciliation: browsers can restore an edited control’s value after the input event, while Vue may skip writing because the model value itself stayed"a". I’ll inspect issue-related tests/history clues and the exact runtime-DOM tests for “same value” input correction. - Assistant
A prior fix explicitly addresses “multiple changes in same tick”; the current source includes that fix’s
prevSetValuecondition. I’ll inspect that commit and current branch chronology to determine whether this Firefox report exposes a different variant, and use blame to see what behavior remains intentionally suppressed. - Assistant
The failure mechanism is now clear: after the model has settled at
"a", one input event emits (for example)"ab"and then"a". The parent’s reactive value ends where it started, so optimized rendering skips the child; becauseuseModelonly force-triggers for transformed setters, the input DOM is never reconciled. Firefox exposes that stale DOM state.I’ll extend the existing force-update condition to also trigger when a changed assignment emits the current prop value. This preserves emission suppression for genuinely repeated assignments while ensuring the controlled child rerenders when a same-tick sequence returns the parent model to its prior value.
- Assistant
The source edit completed, but invoking
pnpmhit an unavailable interactive Corepack download prompt and timed out before formatting. I’ll use the repository-local binaries directly, inspect the resulting diff, and then run the focused unit suite through local Vitest without relying on Corepack. - Assistant
The diff is formatted and clean. Before broader validation, I’ll run the complete
useModelunit file. This covers duplicate sets, same-tick changes, custom getters/setters, local models, and transformed input synchronization—the edge cases most likely affected by broadening the trigger condition. - Assistant
The focused existing suite passes. To verify the reported sequence itself (without committing a test, per the constraints), I’ll create a temporary runtime-DOM spec that renders the equivalent of the two SFCs, dispatches two edits (
"x"then"ab"), and checks that the controlled input returns to"a". I’ll run it against both the original and fixed helper, then delete the temporary file. - Assistant
The temporary file was excluded because the generic
unitproject intentionally omits runtime-DOM tests; cleanup and source restoration succeeded. I’ll inspect Vitest’s project names/environment mapping, then rerun the same temporary reproduction under the correct runtime-DOM project. - Assistant
The correct project is
unit-jsdom. I’ll recreate the temporary spec, demonstrate that the original helper leaves"ab"behind, demonstrate the fix restores"a", and remove all temporary artifacts immediately afterward. - Assistant
The temporary reproduction confirms the bug exactly: the original implementation leaves
"ab", while the fix restores"a". One edge case deserves tightening before final tests: for an uncontrolled/local model,localValueis updated immediately, so the new “same as local” condition could issue a redundant second trigger. I’ll factor the existing parent-control detection into a boolean and restrict forced reconciliation to controlled models, where prop synchronization can actually be skipped. - Assistant
The refined implementation is formatted, lint-clean, and avoids duplicate local-model notifications. I’ll now run both affected suites: all
useModelhelper tests and all runtime-DOMv-modeldirective tests. Then I’ll run the TypeScript project check to catch any inferred-type regressions from the refactor. - Assistant
All targeted validation passed: 14
useModeltests, 28 runtime-DOMv-modeltests, and the full TypeScript no-emit check. I’ll do a final repository hygiene review to ensure the temporary reproduction is gone, only the intended source file changed, and there are no whitespace or generated-file artifacts before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.