Skip to content

Commit 945a543

Browse files
authored
fix(compat): handle v-model deprecation warning with missing appContext (#14203)
close #14202
1 parent dfe667c commit 945a543

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

packages/runtime-core/src/compat/componentVModel.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ShapeFlags, extend } from '@vue/shared'
22
import type { ComponentInternalInstance, ComponentOptions } from '../component'
3+
import { createAppContext } from '../apiCreateApp'
34
import { ErrorCodes, callWithErrorHandling } from '../errorHandling'
45
import type { VNode } from '../vnode'
56
import { 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
}

packages/vue-compat/__tests__/componentVModel.spec.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff 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
})

0 commit comments

Comments
 (0)