fix(compiler-ssr): fix v-html SSR for nullish values

close #10725
This commit is contained in:
Evan You 2024-04-18 12:49:56 +08:00
parent cde7f05787
commit 1ff407676f
No known key found for this signature in database
GPG Key ID: B9D421896CA450FB
2 changed files with 6 additions and 2 deletions

View File

@ -25,7 +25,7 @@ describe('ssr: element', () => {
test('v-html', () => {
expect(getCompiledString(`<div v-html="foo"/>`)).toMatchInlineSnapshot(`
"\`<div>\${
_ctx.foo
(_ctx.foo) ?? ''
}</div>\`"
`)
})

View File

@ -22,6 +22,7 @@ import {
createAssignmentExpression,
createCallExpression,
createCompilerError,
createCompoundExpression,
createConditionalExpression,
createInterpolation,
createSequenceExpression,
@ -188,7 +189,10 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
// special cases with children override
if (prop.type === NodeTypes.DIRECTIVE) {
if (prop.name === 'html' && prop.exp) {
rawChildrenMap.set(node, prop.exp)
rawChildrenMap.set(
node,
createCompoundExpression([`(`, prop.exp, `) ?? ''`]),
)
} else if (prop.name === 'text' && prop.exp) {
node.children = [createInterpolation(prop.exp, prop.loc)]
} else if (prop.name === 'slot') {