Skip to content

Commit 9a742cb

Browse files
committed
only treat binding as domProps on specific elements (fix vuejs#4233)
1 parent f4df893 commit 9a742cb

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

flow/compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ declare type CompilerOptions = {
77
directives?: { [key: string]: Function }; // platform specific directives
88
isUnaryTag?: (tag: string) => ?boolean; // check if a tag is unary for the platform
99
isReservedTag?: (tag: string) => ?boolean; // check if a tag is a native for the platform
10-
mustUseProp?: (attr: string) => ?boolean; // check if an attribute should be bound as a property
10+
mustUseProp?: (tag: string, attr: string) => ?boolean; // check if an attribute should be bound as a property
1111
isPreTag?: (attr: string) => ?boolean; // check if a tag needs to preserve whitespace
1212
getTagNamespace?: (tag: string) => ?string; // check the namespace for a tag
1313
transforms?: Array<Function>; // a list of transforms on parsed AST before codegen

src/compiler/directives/bind.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
export default function bind (el: ASTElement, dir: ASTDirective) {
44
el.wrapData = (code: string) => {
5-
return `_b(${
6-
code
7-
},${
8-
dir.value
9-
}${
5+
return `_b(${code},'${el.tag}',${dir.value}${
106
dir.modifiers && dir.modifiers.prop ? ',true' : ''
117
})`
128
}

src/compiler/parser/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function processAttrs (el) {
379379
name = camelize(name)
380380
if (name === 'innerHtml') name = 'innerHTML'
381381
}
382-
if (isProp || platformMustUseProp(name)) {
382+
if (isProp || platformMustUseProp(el.tag, name)) {
383383
addProp(el, name, value)
384384
} else {
385385
addAttr(el, name, value)

src/core/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type Config = {
1414
isReservedTag: (x?: string) => boolean;
1515
isUnknownElement: (x?: string) => boolean;
1616
getTagNamespace: (x?: string) => string | void;
17-
mustUseProp: (x?: string) => boolean;
17+
mustUseProp: (tag?: string, x?: string) => boolean;
1818
// internal
1919
_assetTypes: Array<string>;
2020
_lifecycleHooks: Array<string>;

src/core/instance/render.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ export function renderMixin (Vue: Class<Component>) {
201201
// apply v-bind object
202202
Vue.prototype._b = function bindProps (
203203
data: any,
204+
tag: string,
204205
value: any,
205206
asProp?: boolean
206207
): VNodeData {
@@ -218,7 +219,7 @@ export function renderMixin (Vue: Class<Component>) {
218219
if (key === 'class' || key === 'style') {
219220
data[key] = value[key]
220221
} else {
221-
const hash = asProp || config.mustUseProp(key)
222+
const hash = asProp || config.mustUseProp(tag, key)
222223
? data.domProps || (data.domProps = {})
223224
: data.attrs || (data.attrs = {})
224225
hash[key] = value[key]

src/platforms/web/util/attrs.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
import { makeMap } from 'shared/util'
44

55
// attributes that should be using props for binding
6-
export const mustUseProp = makeMap('value,selected,checked,muted')
6+
export const mustUseProp = (tag: string, attr: string): boolean => {
7+
return (
8+
(attr === 'value' && (tag === 'input' || tag === 'textarea' || tag === 'option')) ||
9+
(attr === 'selected' && tag === 'option') ||
10+
(attr === 'checked' && tag === 'input') ||
11+
(attr === 'muted' && tag === 'video')
12+
)
13+
}
714

815
export const isEnumeratedAttr = makeMap('contenteditable,draggable,spellcheck')
916

test/unit/modules/compiler/codegen.spec.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ describe('codegen', () => {
8484
it('generate v-bind directive', () => {
8585
assertCodegen(
8686
'<p v-bind="test"></p>',
87-
`with(this){return _h('p',_b({},test))}`
87+
`with(this){return _h('p',_b({},'p',test))}`
8888
)
8989
})
9090

@@ -151,9 +151,15 @@ describe('codegen', () => {
151151
})
152152

153153
it('generate DOM props with v-bind directive', () => {
154+
// input + value
155+
assertCodegen(
156+
'<input :value="msg">',
157+
`with(this){return _h('input',{domProps:{"value":msg}})}`
158+
)
159+
// non input
154160
assertCodegen(
155161
'<p :value="msg">',
156-
`with(this){return _h('p',{domProps:{"value":msg}})}`
162+
`with(this){return _h('p',{attrs:{"value":msg}})}`
157163
)
158164
})
159165

0 commit comments

Comments
 (0)