File tree Expand file tree Collapse file tree 2 files changed +46
-1
lines changed
Expand file tree Collapse file tree 2 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 11import { ShapeFlags , extend } from '@vue/shared'
22import type { ComponentInternalInstance , ComponentOptions } from '../component'
3+ import { createAppContext } from '../apiCreateApp'
34import { ErrorCodes , callWithErrorHandling } from '../errorHandling'
45import type { VNode } from '../vnode'
56import { popWarningContext , pushWarningContext } from '../warning'
@@ -31,7 +32,14 @@ export function convertLegacyVModelProps(vnode: VNode): void {
3132
3233 if ( __DEV__ && ! warnedTypes . has ( comp ) ) {
3334 pushWarningContext ( vnode )
34- warnDeprecation ( DeprecationTypes . COMPONENT_V_MODEL , { type } as any , comp )
35+ warnDeprecation (
36+ DeprecationTypes . COMPONENT_V_MODEL ,
37+ {
38+ type,
39+ appContext : ( vnode . ctx && vnode . ctx . appContext ) || createAppContext ( ) ,
40+ } as any ,
41+ comp ,
42+ )
3543 popWarningContext ( )
3644 warnedTypes . add ( comp )
3745 }
Original file line number Diff line number Diff line change @@ -140,4 +140,41 @@ describe('COMPONENT_V_MODEL', () => {
140140 template : `<input :value="foo" @input="$emit('bar', $event.target.value)">` ,
141141 } )
142142 } )
143+
144+ // #14202
145+ test ( 'should handle v-model deprecation warning with missing appContext' , async ( ) => {
146+ const ChildComponent = {
147+ template : `<div @click="$emit('input', 'new val')">{{ value }}</div>` ,
148+ props : [ 'value' ] ,
149+ }
150+
151+ const vm = new Vue ( {
152+ components : { ChildComponent } ,
153+ data ( ) {
154+ return {
155+ myVal : 'initial' ,
156+ }
157+ } ,
158+ template : `
159+ <div>
160+ <child-component v-model="myVal"></child-component>
161+ </div>
162+ ` ,
163+ } ) . $mount ( ) as any
164+
165+ expect ( vm . $el . textContent ) . toContain ( 'initial' )
166+
167+ expect (
168+ ( deprecationData [ DeprecationTypes . COMPONENT_V_MODEL ] . message as Function ) (
169+ ChildComponent ,
170+ ) ,
171+ ) . toHaveBeenWarned ( )
172+
173+ // Should work correctly
174+ const child = vm . $el . querySelector ( 'div' )
175+ child . click ( )
176+ await nextTick ( )
177+ expect ( vm . myVal ) . toBe ( 'new val' )
178+ expect ( vm . $el . textContent ) . toContain ( 'new val' )
179+ } )
143180} )
You can’t perform that action at this time.
0 commit comments