Repository navigation
fix(vue): honour v-model.lazy on input components - #31804
Open
AdityaxDeore wants to merge 1 commit into
Open
AdityaxDeore wants to merge 1 commit into
AdityaxDeore wants to merge 1 commit into
Conversation
The generated Vue proxies always emit update:modelValue on ionInput and never read modelModifiers, so v-model.lazy updated the bound value on every keystroke instead of committing on change. Wrap the five input proxies (ion-input, ion-textarea, ion-searchbar, ion-input-otp, ion-range) in a shared withLazyModel helper: default behaviour is unchanged, and with .lazy the model commits on ionChange instead, while the user's own ionChange listener still fires. modelValue is only forwarded when the parent provided it, so :value without v-model and v-model bound to undefined keep working. Regression test: packages/vue/test/base/tests/unit/v-model-lazy.spec.ts (8 tests: 5 lazy commits, non-lazy control, user ionChange listener, :value without v-model). Fail-before on the unfixed build: 6 failed / 2 passed; pass-after: 8/8. Full vue3 unit suite: 13 files, 81 tests, all passed. Typecheck, eslint and prettier clean. Fixes ionic-team#31761
|
@AdityaxDeore is attempting to deploy a commit to the Ionic Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #31761
Problem
v-model.lazyonion-input,ion-textarea,ion-searchbar,ion-input-otpandion-rangeupdates the bound value on every keystroke instead of committing on change. The Vue proxies are generated by@stencil/vue-output-targetand itsdefineContainerruntime always emitsupdate:modelValueon the configured model event (ionInputhere) — it never readsmodelModifiers, so.lazyis silently ignored.Fix
Hand-written wrappers around the five generated proxies, sharing one helper (
packages/vue/src/utils/lazy-model.ts):update:modelValue(fired onionInput) is forwarded as before.modelModifiers.lazy, those updates are dropped and the value commits onionChangeinstead, which fires at the same moments as a nativechangeevent.ionChangelistener is still called.modelValueis only forwarded to the inner proxy when the parent actually provided it (checked via the vnode props, sov-modelbound toundefinedstill clears the input). Otherwise the proxy falls back to thevalueprop, so:valuewithoutv-modelkeeps working.Explicit named exports in
packages/vue/src/index.tstake precedence over the generated ones from./proxies..trim/.numberare out of scope for this issue.Testing
New regression test
packages/vue/test/base/tests/unit/v-model-lazy.spec.ts(vitest + @vue/test-utils, run in thevue3test app against the locally built@ionic/vue):ionInput, commit onionChangeionInputwithout.lazy@ionChangelistener still fires with.lazy:valuewithoutv-modelstill rendersFail-before on the unfixed build: 6 failed / 2 passed (the lazy tests failed because
update:modelValuefired onionInput; the listener test failed because the model never committed onionChange). Pass-after: 8/8. Fulltests/unitsuite in the vue3 test app against the fixed build: 13 files, 81 tests, all passed.packages/vuetypecheck, eslint and prettier are clean;coreandpackages/vuebuilds pass.Disclosure: AI coding assistance was used in preparing this change.