Skip to content

Commit 7e2bcc8

Browse files
authored
fix: improve code gen when using cssVars in SSR (#85)
1 parent edff9d8 commit 7e2bcc8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

Diff for: src/transform.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ export async function compileFile(
111111
const [clientScript, bindings] = clientScriptResult
112112
clientCode += clientScript
113113

114-
// script ssr only needs to be performed if using <script setup> where
115-
// the render fn is inlined.
116-
if (descriptor.scriptSetup) {
114+
// script ssr needs to be performed if :
115+
// 1.using <script setup> where the render fn is inlined.
116+
// 2.using cssVars, as it do not need to be injected during SSR.
117+
if (descriptor.scriptSetup || descriptor.cssVars.length > 0) {
117118
const ssrScriptResult = await doCompileScript(
118119
store,
119120
descriptor,
@@ -127,7 +128,7 @@ export async function compileFile(
127128
ssrCode = `/* SSR compile error: ${store.state.errors[0]} */`
128129
}
129130
} else {
130-
// when no <script setup> is used, the script result will be identical.
131+
// the script result will be identical.
131132
ssrCode += clientScript
132133
}
133134

@@ -285,6 +286,7 @@ async function doCompileTemplate(
285286
isTS: boolean
286287
) {
287288
const templateResult = store.compiler.compileTemplate({
289+
isProd: false,
288290
...store.options?.template,
289291
source: descriptor.template!.content,
290292
filename: descriptor.filename,
@@ -293,7 +295,6 @@ async function doCompileTemplate(
293295
slotted: descriptor.slotted,
294296
ssr,
295297
ssrCssVars: descriptor.cssVars,
296-
isProd: false,
297298
compilerOptions: {
298299
...store.options?.template?.compilerOptions,
299300
bindingMetadata,

0 commit comments

Comments
 (0)