diff --git a/packages/compiler-ssr/__tests__/ssrElement.spec.ts b/packages/compiler-ssr/__tests__/ssrElement.spec.ts
index 723ef7b3592..f1d509acfb0 100644
--- a/packages/compiler-ssr/__tests__/ssrElement.spec.ts
+++ b/packages/compiler-ssr/__tests__/ssrElement.spec.ts
@@ -337,6 +337,39 @@ describe('ssr: element', () => {
`)
})
+ test('custom dir with v-text', () => {
+ expect(getCompiledString(`
`))
+ .toMatchInlineSnapshot(`
+ "\`\${
+ _ssrInterpolate(_ctx.foo)
+ }
\`"
+ `)
+ })
+
+ test('custom dir with v-text and normal attrs', () => {
+ expect(getCompiledString(``))
+ .toMatchInlineSnapshot(`
+ "\`\${
+ _ssrInterpolate(_ctx.foo)
+ }
\`"
+ `)
+ })
+
+ test('mulptiple custom dirs with v-text', () => {
+ expect(getCompiledString(``))
+ .toMatchInlineSnapshot(`
+ "\`\${
+ _ssrInterpolate(_ctx.foo)
+ }
\`"
+ `)
+ })
+
test('custom dir with object v-bind', () => {
expect(getCompiledString(``))
.toMatchInlineSnapshot(`
diff --git a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts
index 6a028953ed6..4a12b0f7ba7 100644
--- a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts
+++ b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts
@@ -28,6 +28,7 @@ import {
createSequenceExpression,
createSimpleExpression,
createTemplateLiteral,
+ findDir,
hasDynamicKeyVBind,
isStaticArgOf,
isStaticExp,
@@ -164,24 +165,28 @@ export const ssrTransformElement: NodeTransform = (node, context) => {
]
}
} else if (directives.length && !node.children.length) {
- const tempId = `_temp${context.temps++}`
- propsExp.arguments = [
- createAssignmentExpression(
- createSimpleExpression(tempId, false),
- mergedProps,
- ),
- ]
- rawChildrenMap.set(
- node,
- createConditionalExpression(
- createSimpleExpression(`"textContent" in ${tempId}`, false),
- createCallExpression(context.helper(SSR_INTERPOLATE), [
- createSimpleExpression(`${tempId}.textContent`, false),
- ]),
- createSimpleExpression(`${tempId}.innerHTML ?? ''`, false),
- false,
- ),
- )
+ // v-text directive has higher priority than the merged props
+ const vText = findDir(node, 'text')
+ if (!vText) {
+ const tempId = `_temp${context.temps++}`
+ propsExp.arguments = [
+ createAssignmentExpression(
+ createSimpleExpression(tempId, false),
+ mergedProps,
+ ),
+ ]
+ rawChildrenMap.set(
+ node,
+ createConditionalExpression(
+ createSimpleExpression(`"textContent" in ${tempId}`, false),
+ createCallExpression(context.helper(SSR_INTERPOLATE), [
+ createSimpleExpression(`${tempId}.textContent`, false),
+ ]),
+ createSimpleExpression(`${tempId}.innerHTML ?? ''`, false),
+ false,
+ ),
+ )
+ }
}
if (needTagForRuntime) {