From 613e84535e2a075b87c3dc83a39b57030cc52f4d Mon Sep 17 00:00:00 2001 From: Daniel Jun Suguimoto Date: Tue, 18 Feb 2020 00:09:36 -0300 Subject: [PATCH 1/2] fix(ssr): textarea keeps undefined/null values --- src/platforms/web/server/modules/dom-props.js | 2 +- test/ssr/ssr-string.spec.js | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/platforms/web/server/modules/dom-props.js b/src/platforms/web/server/modules/dom-props.js index 57c18eefc89..b020b5a2b1a 100644 --- a/src/platforms/web/server/modules/dom-props.js +++ b/src/platforms/web/server/modules/dom-props.js @@ -27,7 +27,7 @@ export default function renderDOMProps (node: VNodeWithData): string { setText(node, props[key], true) } else if (key === 'textContent') { setText(node, props[key], false) - } else if (key === 'value' && node.tag === 'textarea') { + } else if (key === 'value' && node.tag === 'textarea' && isDef(props[key])) { setText(node, props[key], false) } else { // $flow-disable-line (WTF?) diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index e18ca2aead9..b24f7e024b5 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -1594,6 +1594,25 @@ describe('SSR: renderToString', () => { renderToString(vueInstance, err => done(err)) }) + + it('undefined v-model with textarea', done => { + renderVmWithOptions({ + render (h) { + return h('div', [ + h('textarea', { + domProps: { + value: null + } + }) + ]) + } + }, result => { + expect(result).toContain( + '
' + ) + done() + }) + }) }) function renderVmWithOptions (options, cb) { From ec792389b6f1d577c205448736a2231c3aa90471 Mon Sep 17 00:00:00 2001 From: Daniel Jun Suguimoto Date: Wed, 19 Feb 2020 14:21:29 -0300 Subject: [PATCH 2/2] refactor(ssr): Code review changes for null values in textareas --- src/platforms/web/server/modules/dom-props.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platforms/web/server/modules/dom-props.js b/src/platforms/web/server/modules/dom-props.js index b020b5a2b1a..6d92badcb85 100644 --- a/src/platforms/web/server/modules/dom-props.js +++ b/src/platforms/web/server/modules/dom-props.js @@ -2,7 +2,7 @@ import VNode from 'core/vdom/vnode' import { renderAttr } from './attrs' -import { isDef, isUndef, extend } from 'shared/util' +import { isDef, isUndef, extend, toString } from 'shared/util' import { propsToAttrMap, isRenderableAttr } from '../util' export default function renderDOMProps (node: VNodeWithData): string { @@ -27,8 +27,8 @@ export default function renderDOMProps (node: VNodeWithData): string { setText(node, props[key], true) } else if (key === 'textContent') { setText(node, props[key], false) - } else if (key === 'value' && node.tag === 'textarea' && isDef(props[key])) { - setText(node, props[key], false) + } else if (key === 'value' && node.tag === 'textarea') { + setText(node, toString(props[key]), false) } else { // $flow-disable-line (WTF?) const attr = propsToAttrMap[key] || key.toLowerCase()