Skip to content

Commit 0f0cf53

Browse files
committed
fix(cssVars): cssVarName should keep backslashe in ssr dev mode
1 parent 3be4e3c commit 0f0cf53

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,12 @@ export default {
10031003
setup(__props) {
10041004
10051005
const count = ref(0)
1006+
const style = { color: 'red' }
10061007
10071008
return (_ctx, _push, _parent, _attrs) => {
10081009
const _cssVars = { style: {
1009-
\\"--xxxxxxxx-count\\": (count.value)
1010+
\\"--xxxxxxxx-count\\": (count.value),
1011+
\\"--xxxxxxxx-style\\\\\\\\.color\\": (style.color)
10101012
}}
10111013
_push(\`<!--[--><div\${
10121014
_ssrRenderAttrs(_cssVars)

packages/compiler-sfc/__tests__/compileScript.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,15 @@ describe('SFC compile <script setup>', () => {
777777
<script setup>
778778
import { ref } from 'vue'
779779
const count = ref(0)
780+
const style = { color: 'red' }
780781
</script>
781782
<template>
782783
<div>{{ count }}</div>
783784
<div>static</div>
784785
</template>
785786
<style>
786787
div { color: v-bind(count) }
788+
span { color: v-bind(style.color) }
787789
</style>
788790
`,
789791
{
@@ -798,6 +800,7 @@ describe('SFC compile <script setup>', () => {
798800
expect(content).toMatch(`ssrInterpolate`)
799801
expect(content).not.toMatch(`useCssVars`)
800802
expect(content).toMatch(`"--${mockId}-count": (count.value)`)
803+
expect(content).toMatch(`"--${mockId}-style\\\\.color": (style.color)`)
801804
assertCode(content)
802805
})
803806

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ export function genCssVarsFromList(
2121
isSSR = false
2222
): string {
2323
return `{\n ${vars
24-
.map(
25-
key => `"${isSSR ? `--` : ``}${genVarName(id, key, isProd)}": (${key})`
26-
)
24+
.map(key => {
25+
const varName = genVarName(id, key, isProd)
26+
return `"${isSSR ? `--` : ``}${
27+
isSSR && !isProd ? varName.replace(/\\/g, '\\\\') : varName
28+
}": (${key})`
29+
})
2730
.join(',\n ')}\n}`
2831
}
2932

0 commit comments

Comments
 (0)