Skip to content

Commit

Permalink
fix(compiler-ssr): fix v-html SSR for nullish values
Browse files Browse the repository at this point in the history
close #10725
  • Loading branch information
yyx990803 committed Apr 18, 2024
1 parent cde7f05 commit 1ff4076
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/compiler-ssr/__tests__/ssrElement.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ssr: element', () => {
test('v-html', () => {
expect(getCompiledString(`<div v-html="foo"/>`)).toMatchInlineSnapshot(`
"\`<div>\${
_ctx.foo
(_ctx.foo) ?? ''
}</div>\`"
`)
})
Expand Down
6 changes: 5 additions & 1 deletion packages/compiler-ssr/src/transforms/ssrTransformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
createAssignmentExpression,
createCallExpression,
createCompilerError,
createCompoundExpression,
createConditionalExpression,
createInterpolation,
createSequenceExpression,
Expand Down Expand Up @@ -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') {
Expand Down

0 comments on commit 1ff4076

Please sign in to comment.