@@ -51,51 +51,48 @@ export function patchDOMProp(
51
51
return
52
52
}
53
53
54
+ let needRemove = false
54
55
if ( value === '' || value == null ) {
55
56
const type = typeof el [ key ]
56
57
if ( type === 'boolean' ) {
57
58
// e.g. <select multiple> compiles to { multiple: '' }
58
- el [ key ] = includeBooleanAttr ( value )
59
- return
59
+ value = includeBooleanAttr ( value )
60
60
} else if ( value == null && type === 'string' ) {
61
61
// e.g. <div :id="null">
62
- el [ key ] = ''
63
- el . removeAttribute ( key )
64
- return
62
+ value = ''
63
+ needRemove = true
65
64
} else if ( type === 'number' ) {
66
65
// e.g. <img :width="null">
67
66
// the value of some IDL attr must be greater than 0, e.g. input.size = 0 -> error
68
- try {
69
- el [ key ] = 0
70
- } catch { }
71
- el . removeAttribute ( key )
72
- return
67
+ value = 0
68
+ needRemove = true
73
69
}
74
- }
75
-
76
- if (
77
- __COMPAT__ &&
78
- value === false &&
79
- compatUtils . isCompatEnabled (
80
- DeprecationTypes . ATTR_FALSE_VALUE ,
81
- parentComponent
82
- )
83
- ) {
84
- const type = typeof el [ key ]
85
- if ( type === 'string' || type === 'number' ) {
86
- __DEV__ &&
87
- compatUtils . warnDeprecation (
88
- DeprecationTypes . ATTR_FALSE_VALUE ,
89
- parentComponent ,
90
- key
91
- )
92
- el [ key ] = type === 'number' ? 0 : ''
93
- el . removeAttribute ( key )
94
- return
70
+ } else {
71
+ if (
72
+ __COMPAT__ &&
73
+ value === false &&
74
+ compatUtils . isCompatEnabled (
75
+ DeprecationTypes . ATTR_FALSE_VALUE ,
76
+ parentComponent
77
+ )
78
+ ) {
79
+ const type = typeof el [ key ]
80
+ if ( type === 'string' || type === 'number' ) {
81
+ __DEV__ &&
82
+ compatUtils . warnDeprecation (
83
+ DeprecationTypes . ATTR_FALSE_VALUE ,
84
+ parentComponent ,
85
+ key
86
+ )
87
+ value = type === 'number' ? 0 : ''
88
+ needRemove = true
89
+ }
95
90
}
96
91
}
97
92
98
- // some properties perform value validation and throw
93
+ // some properties perform value validation and throw,
94
+ // some properties has getter, no setter, will error in 'use strict'
95
+ // eg. <select :type="null"></select> <select :willValidate="null"></select>
99
96
try {
100
97
el [ key ] = value
101
98
} catch ( e : any ) {
@@ -107,4 +104,5 @@ export function patchDOMProp(
107
104
)
108
105
}
109
106
}
107
+ needRemove && el . removeAttribute ( key )
110
108
}
0 commit comments