diff --git a/packages/compiler-ssr/__tests__/ssrElement.spec.ts b/packages/compiler-ssr/__tests__/ssrElement.spec.ts index 55eaa50647c..30e75e36f2b 100644 --- a/packages/compiler-ssr/__tests__/ssrElement.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrElement.spec.ts @@ -112,6 +112,15 @@ describe('ssr: element', () => { `) }) + test('v-bind:class + static class', () => { + expect(getCompiledString(`
`)) + .toMatchInlineSnapshot(` + "\`\`" + `) + }) + test('v-bind:style', () => { expect(getCompiledString(``)) .toMatchInlineSnapshot(` diff --git a/packages/compiler-ssr/src/transforms/ssrInjectCssVars.ts b/packages/compiler-ssr/src/transforms/ssrInjectCssVars.ts index 0e6540c3b66..c848598a286 100644 --- a/packages/compiler-ssr/src/transforms/ssrInjectCssVars.ts +++ b/packages/compiler-ssr/src/transforms/ssrInjectCssVars.ts @@ -15,8 +15,8 @@ export const ssrInjectCssVars: NodeTransform = (node, context) => { return } - // _cssVars is initailized once per render function - // the code is injected in ssrCodegenTrasnform when creating the + // _cssVars is initialized once per render function + // the code is injected in ssrCodegenTransform when creating the // ssr transform context if (node.type === NodeTypes.ROOT) { context.identifiers._cssVars = 1 diff --git a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts index e2f2ed8de84..e036671fcda 100644 --- a/packages/compiler-ssr/src/transforms/ssrTransformElement.ts +++ b/packages/compiler-ssr/src/transforms/ssrTransformElement.ts @@ -324,9 +324,10 @@ function removeStaticBinding( tag: TemplateLiteral['elements'], binding: string ) { - const i = tag.findIndex( - e => typeof e === 'string' && e.startsWith(` ${binding}=`) - ) + const regExp = new RegExp(`^ ${binding}=".+"$`) + + const i = tag.findIndex(e => typeof e === 'string' && regExp.test(e)) + if (i > -1) { tag.splice(i, 1) } diff --git a/packages/server-renderer/__tests__/renderToString.spec.ts b/packages/server-renderer/__tests__/renderToString.spec.ts index 25704eeee46..a7756a89e6b 100644 --- a/packages/server-renderer/__tests__/renderToString.spec.ts +++ b/packages/server-renderer/__tests__/renderToString.spec.ts @@ -142,6 +142,24 @@ describe('ssr: renderToString', () => { ) }) + test('template components with dynamic class attribute after static', async () => { + const app = createApp({ + template: `