Skip to content

Commit b8bd149

Browse files
fix(ssr): textarea keeps undefined/null values (#11121)
* fix(ssr): textarea keeps undefined/null values * refactor(ssr): Code review changes for null values in textareas
1 parent 67825c2 commit b8bd149

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import VNode from 'core/vdom/vnode'
44
import { renderAttr } from './attrs'
5-
import { isDef, isUndef, extend } from 'shared/util'
5+
import { isDef, isUndef, extend, toString } from 'shared/util'
66
import { propsToAttrMap, isRenderableAttr } from '../util'
77

88
export default function renderDOMProps (node: VNodeWithData): string {
@@ -28,7 +28,7 @@ export default function renderDOMProps (node: VNodeWithData): string {
2828
} else if (key === 'textContent') {
2929
setText(node, props[key], false)
3030
} else if (key === 'value' && node.tag === 'textarea') {
31-
setText(node, props[key], false)
31+
setText(node, toString(props[key]), false)
3232
} else {
3333
// $flow-disable-line (WTF?)
3434
const attr = propsToAttrMap[key] || key.toLowerCase()

test/ssr/ssr-string.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,25 @@ describe('SSR: renderToString', () => {
15941594

15951595
renderToString(vueInstance, err => done(err))
15961596
})
1597+
1598+
it('undefined v-model with textarea', done => {
1599+
renderVmWithOptions({
1600+
render (h) {
1601+
return h('div', [
1602+
h('textarea', {
1603+
domProps: {
1604+
value: null
1605+
}
1606+
})
1607+
])
1608+
}
1609+
}, result => {
1610+
expect(result).toContain(
1611+
'<div data-server-rendered="true"><textarea></textarea></div>'
1612+
)
1613+
done()
1614+
})
1615+
})
15971616
})
15981617

15991618
function renderVmWithOptions (options, cb) {

0 commit comments

Comments
 (0)