Skip to content

Commit

Permalink
fix(ssr): should render 0 as valid value for style property with unit
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 12, 2019
1 parent 584e89d commit aef5b4e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/platforms/web/server/modules/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions test/ssr/ssr-string.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<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()
})
Expand Down

0 comments on commit aef5b4e

Please sign in to comment.