From aef5b4e47811cb842315bd27d6919650da45279b Mon Sep 17 00:00:00 2001 From: Evan You Date: Sat, 12 Jan 2019 02:07:17 -0500 Subject: [PATCH] fix(ssr): should render 0 as valid value for style property with unit --- src/platforms/web/server/modules/style.js | 3 ++- test/ssr/ssr-string.spec.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/platforms/web/server/modules/style.js b/src/platforms/web/server/modules/style.js index 4d32562823a..4c7c2bbbadc 100644 --- a/src/platforms/web/server/modules/style.js +++ b/src/platforms/web/server/modules/style.js @@ -23,7 +23,8 @@ export function genStyle (style: Object): string { function normalizeValue(key: string, value: any): string { if ( typeof value === 'string' || - (typeof value === 'number' && noUnitNumericStyleProps[key]) + (typeof value === 'number' && noUnitNumericStyleProps[key]) || + value === 0 ) { return `${key}:${value};` } else { diff --git a/test/ssr/ssr-string.spec.js b/test/ssr/ssr-string.spec.js index 75bcc8cb1f1..975197b6c1b 100644 --- a/test/ssr/ssr-string.spec.js +++ b/test/ssr/ssr-string.spec.js @@ -1529,13 +1529,14 @@ describe('SSR: renderToString', () => { data: { style: { opacity: 0, // valid, opacity is unit-less - top: 0, // invalid, top requires unit + top: 0, // valid, top requires unit but 0 is allowed + left: 10, // invalid, left requires a unit marginTop: '10px' // valid } } }, result => { expect(result).toContain( - '
' + '
' ) done() })