Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49b6313

Browse files
committed
fix(compiler-sfc): ensure css custom properties do not start with a digit
1 parent 75220c7 commit 49b6313

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

‎packages/compiler-sfc/__tests__/cssVars.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ describe('CSS vars injection', () => {
109109
{ isProd: true },
110110
)
111111
expect(content).toMatch(`_useCssVars(_ctx => ({
112-
"4003f1a6": (_ctx.color),
113-
"41b6490a": (_ctx.font.size)
112+
"v4003f1a6": (_ctx.color),
113+
"v41b6490a": (_ctx.font.size)
114114
}))}`)
115115

116116
const { code } = compileStyle({
@@ -124,8 +124,8 @@ describe('CSS vars injection', () => {
124124
})
125125
expect(code).toMatchInlineSnapshot(`
126126
".foo {
127-
color: var(--4003f1a6);
128-
font-size: var(--41b6490a);
127+
color: var(--v4003f1a6);
128+
font-size: var(--v41b6490a);
129129
}"
130130
`)
131131
})

‎packages/compiler-sfc/src/style/cssVars.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ function genVarName(
4040
isSSR = false,
4141
): string {
4242
if (isProd) {
43-
return hash(id + raw)
43+
// hash must not start with a digit to comply with CSS custom property naming rules
44+
return hash(id + raw).replace(/^\d/, r => `v${r}`)
4445
} else {
4546
// escape ASCII Punctuation & Symbols
4647
// #7823 need to double-escape in SSR because the attributes are rendered

0 commit comments

Comments
 (0)