From: Mathieu TUDISCO Date: Tue, 13 Oct 2020 20:25:15 +0000 (+0200) Subject: fix(compiler-ssr): fix SSR issue when dynamic and static class co-exist (#2354) X-Git-Tag: v3.0.1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8539c0bf32e86fb16349a210f878681579fb7976;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-ssr): fix SSR issue when dynamic and static class co-exist (#2354) --- diff --git a/packages/compiler-ssr/__tests__/ssrElement.spec.ts b/packages/compiler-ssr/__tests__/ssrElement.spec.ts index 55eaa50647..30e75e36f2 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 0e6540c3b6..c848598a28 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 e2f2ed8de8..e036671fcd 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 25704eeee4..a7756a89e6 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: `
` + }) + expect(await renderToString(app)).toBe( + `
` + ) + }) + + test('template components with dynamic class attribute before static', async () => { + const app = createApp({ + template: `
` + }) + expect(await renderToString(app)).toBe( + `
` + ) + }) + test('mixing optimized / vnode / template components', async () => { const OptimizedChild = { props: ['msg'],