Browse Source

fix(ssr): should render 0 as valid value for style property with unit

Evan You 7 years ago
parent
commit
aef5b4e478
2 changed files with 5 additions and 3 deletions
  1. 2 1
      src/platforms/web/server/modules/style.js
  2. 3 2
      test/ssr/ssr-string.spec.js

+ 2 - 1
src/platforms/web/server/modules/style.js

@@ -23,7 +23,8 @@ export function genStyle (style: Object): string {
 function normalizeValue(key: string, value: any): string {
 function normalizeValue(key: string, value: any): string {
   if (
   if (
     typeof value === 'string' ||
     typeof value === 'string' ||
-    (typeof value === 'number' && noUnitNumericStyleProps[key])
+    (typeof value === 'number' && noUnitNumericStyleProps[key]) ||
+    value === 0
   ) {
   ) {
     return `${key}:${value};`
     return `${key}:${value};`
   } else {
   } else {

+ 3 - 2
test/ssr/ssr-string.spec.js

@@ -1529,13 +1529,14 @@ describe('SSR: renderToString', () => {
       data: {
       data: {
         style: {
         style: {
           opacity: 0, // valid, opacity is unit-less
           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
           marginTop: '10px' // valid
         }
         }
       }
       }
     }, result => {
     }, result => {
       expect(result).toContain(
       expect(result).toContain(
-        '<div data-server-rendered="true" style="opacity:0;margin-top:10px;"></div>'
+        '<div data-server-rendered="true" style="opacity:0;top:0;margin-top:10px;"></div>'
       )
       )
       done()
       done()
     })
     })