diff --git a/src/platforms/web/server/modules/class.js b/src/platforms/web/server/modules/class.js index ba7099d10e2..69a84d7bdf7 100644 --- a/src/platforms/web/server/modules/class.js +++ b/src/platforms/web/server/modules/class.js @@ -3,7 +3,8 @@ import { genClassForVnode } from 'web/util/index' export default function renderClass (node: VNodeWithData): ?string { - if (node.data.class || node.data.staticClass) { - return ` class="${genClassForVnode(node)}"` + const classList = genClassForVnode(node) + if (classList) { + return ` class="${classList}"` } } diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index fbd1d8f55b9..06fa7da10b5 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -57,6 +57,42 @@ describe('SSR: renderToString', () => { }) }) + it('custome component class', done => { + renderVmWithOptions({ + template: '
', + components: { + cmp: { + render: h => h('div', 'test') + } + } + }, result => { + expect(result).toContain('
test
') + done() + }) + }) + + it('nested component class', done => { + renderVmWithOptions({ + template: '', + data: { cls: { 'success': 1 }}, + components: { + cmp: { + render: h => h('div', [h('nested', { staticClass: 'nested', 'class': { 'error': 1 }})]), + components: { + nested: { + render: h => h('div', { staticClass: 'inner' }, 'test') + } + } + } + } + }, result => { + expect(result).toContain('
' + + '
test
' + + '
') + done() + }) + }) + it('dynamic style', done => { renderVmWithOptions({ template: '
',