Skip to content

Commit 79c0d7b

Browse files
committed
fix(ssr): properly render textarea value
partial fix for #6986
1 parent 53b77f8 commit 79c0d7b

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/platforms/web/server/modules/dom-props.js

+3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ export default function renderDOMProps (node: VNodeWithData): string {
2727
setText(node, props[key], true)
2828
} else if (key === 'textContent') {
2929
setText(node, props[key], false)
30+
} else if (key === 'value' && node.tag === 'textarea') {
31+
setText(node, props[key], false)
3032
} else {
33+
// $flow-disable-line (WTF?)
3134
const attr = propsToAttrMap[key] || key.toLowerCase()
3235
if (isRenderableAttr(attr) &&
3336
// avoid rendering double-bound props/attrs twice

src/server/optimizing-compiler/codegen.js

+3
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ function childrenToSegments (el, state): Array<StringSegment> {
205205
if ((binding = el.attrsMap['v-text'])) {
206206
return [{ type: INTERPOLATION, value: `_s(${binding})` }]
207207
}
208+
if (el.tag === 'textarea' && (binding = el.attrsMap['v-model'])) {
209+
return [{ type: INTERPOLATION, value: `_s(${binding})` }]
210+
}
208211
return el.children
209212
? nodesToSegments(el.children, state)
210213
: []

src/server/optimizing-compiler/modules.js

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export function applyModelTransform (el: ASTElement, state: CodegenState) {
3131
const dir = el.directives[i]
3232
if (dir.name === 'model') {
3333
state.directives.model(el, dir, state.warn)
34+
// remove value for textarea as its converted to text
35+
if (el.tag === 'textarea' && el.props) {
36+
el.props = el.props.filter(p => p.name !== 'value')
37+
}
3438
break
3539
}
3640
}

test/ssr/ssr-string.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,31 @@ describe('SSR: renderToString', () => {
10091009
done()
10101010
})
10111011
})
1012+
1013+
it('render v-model with textarea', done => {
1014+
renderVmWithOptions({
1015+
data: { foo: 'bar' },
1016+
template: '<div><textarea v-model="foo"></textarea></div>'
1017+
}, result => {
1018+
expect(result).toContain('<textarea>bar</textarea>')
1019+
done()
1020+
})
1021+
})
1022+
1023+
it('render v-model with textarea (non-optimized)', done => {
1024+
renderVmWithOptions({
1025+
render (h) {
1026+
return h('textarea', {
1027+
domProps: {
1028+
value: 'foo'
1029+
}
1030+
})
1031+
}
1032+
}, result => {
1033+
expect(result).toContain('<textarea data-server-rendered="true">foo</textarea>')
1034+
done()
1035+
})
1036+
})
10121037
})
10131038

10141039
function renderVmWithOptions (options, cb) {

0 commit comments

Comments
 (0)