Skip to content

Commit 09106f0

Browse files
committed
fix(ssr): handle v-text/v-html with non-string value
fix #6572
1 parent 7116af4 commit 09106f0

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/server/optimizing-compiler/codegen.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,10 @@ function elementToOpenTagSegments (el, state): Array<StringSegment> {
200200
function childrenToSegments (el, state): Array<StringSegment> {
201201
let binding
202202
if ((binding = el.attrsMap['v-html'])) {
203-
return [{ type: EXPRESSION, value: binding }]
203+
return [{ type: EXPRESSION, value: `_s(${binding})` }]
204204
}
205205
if ((binding = el.attrsMap['v-text'])) {
206-
return [{ type: INTERPOLATION, value: binding }]
206+
return [{ type: INTERPOLATION, value: `_s(${binding})` }]
207207
}
208208
return el.children
209209
? nodesToSegments(el.children, state)

test/ssr/ssr-string.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ describe('SSR: renderToString', () => {
374374
})
375375
})
376376

377+
it('v-html with null value', done => {
378+
renderVmWithOptions({
379+
template: '<div><div v-html="text"></div></div>',
380+
data: {
381+
text: null
382+
}
383+
}, result => {
384+
expect(result).toContain('<div data-server-rendered="true"><div></div></div>')
385+
done()
386+
})
387+
})
388+
377389
it('v-text', done => {
378390
renderVmWithOptions({
379391
template: '<div><div v-text="text"></div></div>',
@@ -386,6 +398,18 @@ describe('SSR: renderToString', () => {
386398
})
387399
})
388400

401+
it('v-text with null value', done => {
402+
renderVmWithOptions({
403+
template: '<div><div v-text="text"></div></div>',
404+
data: {
405+
text: null
406+
}
407+
}, result => {
408+
expect(result).toContain('<div data-server-rendered="true"><div></div></div>')
409+
done()
410+
})
411+
})
412+
389413
it('child component (hoc)', done => {
390414
renderVmWithOptions({
391415
template: '<child class="foo" :msg="msg"></child>',

0 commit comments

Comments
 (0)