Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(normalizaProp): support css variable as number #6636

Merged
merged 5 commits into from Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/server-renderer/__tests__/ssrRenderAttrs.spec.ts
Expand Up @@ -143,10 +143,12 @@ describe('ssr: renderStyle', () => {
expect(
ssrRenderAttrs({
style: {
color: 'red'
color: 'red',
'--a': 2,
'-webkit-line-clamp': 2
}
})
).toBe(` style="color:red;"`)
).toBe(` style="color:red;--a:2;-webkit-line-clamp:2;"`)
})

test('standalone', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/domAttrConfig.ts
Expand Up @@ -63,6 +63,7 @@ export const isNoUnitNumericStyleProp = /*#__PURE__*/ makeMap(
`grid-row,grid-row-end,grid-row-span,grid-row-start,grid-column,` +
`grid-column-end,grid-column-span,grid-column-start,font-weight,line-clamp,` +
`line-height,opacity,order,orphans,tab-size,widows,z-index,zoom,` +
`-webkit-line-clamp,` +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only adding this doesn't make sense, since every property here are non-prefixed standard properties. There are most likely other prefixed versions of some other properties that can be treated as numbers, and it is impractical for us to support all of them.

I think just supporting custom properties is good enough in this PR. Whether we want to support vendor-prefixed properties is a separate problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'll remove it.

// SVG
`fill-opacity,flood-opacity,stop-opacity,stroke-dasharray,stroke-dashoffset,` +
`stroke-miterlimit,stroke-opacity,stroke-width`
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/normalizeProp.ts
Expand Up @@ -53,7 +53,8 @@ export function stringifyStyle(
const normalizedKey = key.startsWith(`--`) ? key : hyphenate(key)
if (
isString(value) ||
(typeof value === 'number' && isNoUnitNumericStyleProp(normalizedKey))
(typeof value === 'number' &&
(isNoUnitNumericStyleProp(normalizedKey) || key.startsWith(`--`)))
) {
// only render valid values
ret += `${normalizedKey}:${value};`
Expand Down