Skip to content

Commit 1ff4076

Browse files
committedApr 18, 2024··
fix(compiler-ssr): fix v-html SSR for nullish values
close #10725
1 parent cde7f05 commit 1ff4076

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed
 

‎packages/compiler-ssr/__tests__/ssrElement.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('ssr: element', () => {
2525
test('v-html', () => {
2626
expect(getCompiledString(`<div v-html="foo"/>`)).toMatchInlineSnapshot(`
2727
"\`<div>\${
28-
_ctx.foo
28+
(_ctx.foo) ?? ''
2929
}</div>\`"
3030
`)
3131
})

‎packages/compiler-ssr/src/transforms/ssrTransformElement.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
createAssignmentExpression,
2323
createCallExpression,
2424
createCompilerError,
25+
createCompoundExpression,
2526
createConditionalExpression,
2627
createInterpolation,
2728
createSequenceExpression,
@@ -188,7 +189,10 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
188189
// special cases with children override
189190
if (prop.type === NodeTypes.DIRECTIVE) {
190191
if (prop.name === 'html' && prop.exp) {
191-
rawChildrenMap.set(node, prop.exp)
192+
rawChildrenMap.set(
193+
node,
194+
createCompoundExpression([`(`, prop.exp, `) ?? ''`]),
195+
)
192196
} else if (prop.name === 'text' && prop.exp) {
193197
node.children = [createInterpolation(prop.exp, prop.loc)]
194198
} else if (prop.name === 'slot') {

0 commit comments

Comments
 (0)
Please sign in to comment.