Skip to content

Commit 0e8e40a

Browse files
committed
preserve reactivity for initially invalid props (close vuejs#2580)
1 parent 25e4995 commit 0e8e40a

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/compiler/compile-props.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,10 @@ export function initProp (vm, prop, value) {
224224
if (value === undefined) {
225225
value = getPropDefaultValue(vm, prop.options)
226226
}
227-
if (assertProp(prop, value)) {
228-
defineReactive(vm, key, value)
227+
if (!assertProp(prop, value, vm)) {
228+
value = undefined
229229
}
230+
defineReactive(vm, key, value)
230231
}
231232

232233
/**
@@ -265,9 +266,10 @@ function getPropDefaultValue (vm, options) {
265266
*
266267
* @param {Object} prop
267268
* @param {*} value
269+
* @param {Vue} vm
268270
*/
269271

270-
export function assertProp (prop, value) {
272+
export function assertProp (prop, value, vm) {
271273
if (
272274
!prop.options.required && ( // non-required
273275
prop.raw === null || // abscent
@@ -304,20 +306,22 @@ export function assertProp (prop, value) {
304306
}
305307
}
306308
if (!valid) {
307-
process.env.NODE_ENV !== 'production' && warn(
308-
'Invalid prop: type check failed for ' +
309-
prop.path + '="' + prop.raw + '".' +
310-
' Expected ' + formatType(expectedType) +
311-
', got ' + formatValue(value) + '.'
312-
)
309+
if (process.env.NODE_ENV !== 'production') {
310+
warn(
311+
'Invalid prop: type check failed for prop "' + prop.name + '"' +
312+
(vm.$options.name ? ' on component <' + hyphenate(vm.$options.name) + '>.' : '.') +
313+
' Expected ' + formatType(expectedType) +
314+
', got ' + formatValue(value) + '.'
315+
)
316+
}
313317
return false
314318
}
315319
var validator = options.validator
316320
if (validator) {
317321
if (!validator(value)) {
318322
process.env.NODE_ENV !== 'production' && warn(
319-
'Invalid prop: custom validator check failed for ' +
320-
prop.path + '="' + prop.raw + '"'
323+
'Invalid prop: custom validator check failed for prop "' + prop.name + '"' +
324+
(vm.$options.name ? ' on component <' + hyphenate(vm.$options.name) + '>.' : '.')
321325
)
322326
return false
323327
}

src/directives/internal/prop.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
parentKey,
2929
function (val) {
3030
val = coerceProp(prop, val)
31-
if (assertProp(prop, val)) {
31+
if (assertProp(prop, val, child)) {
3232
if (isSimple) {
3333
withoutConversion(() => {
3434
child[childKey] = val

0 commit comments

Comments
 (0)