File tree 3 files changed +70
-2
lines changed
3 files changed +70
-2
lines changed Original file line number Diff line number Diff line change @@ -272,5 +272,73 @@ describe('CSS vars injection', () => {
272
272
`export default {\n setup(__props, { expose: __expose }) {\n __expose();\n\n_useCssVars(_ctx => ({\n "xxxxxxxx-background": (_unref(background))\n}))`
273
273
)
274
274
} )
275
+
276
+ describe ( 'skip codegen in SSR' , ( ) => {
277
+ test ( 'script setup, inline' , ( ) => {
278
+ const { content } = compileSFCScript (
279
+ `<script setup>
280
+ let size = 1
281
+ </script>\n` +
282
+ `<style>
283
+ div {
284
+ font-size: v-bind(size);
285
+ }
286
+ </style>` ,
287
+ {
288
+ inlineTemplate : true ,
289
+ templateOptions : {
290
+ ssr : true
291
+ }
292
+ }
293
+ )
294
+ expect ( content ) . not . toMatch ( `_useCssVars` )
295
+ } )
296
+
297
+ // #6926
298
+ test ( 'script, non-inline' , ( ) => {
299
+ const { content } = compileSFCScript (
300
+ `<script setup>
301
+ let size = 1
302
+ </script>\n` +
303
+ `<style>
304
+ div {
305
+ font-size: v-bind(size);
306
+ }
307
+ </style>` ,
308
+ {
309
+ inlineTemplate : false ,
310
+ templateOptions : {
311
+ ssr : true
312
+ }
313
+ }
314
+ )
315
+ expect ( content ) . not . toMatch ( `_useCssVars` )
316
+ } )
317
+
318
+ test ( 'normal script' , ( ) => {
319
+ const { content } = compileSFCScript (
320
+ `<script>
321
+ export default {
322
+ setup() {
323
+ return {
324
+ size: ref('100px')
325
+ }
326
+ }
327
+ }
328
+ </script>\n` +
329
+ `<style>
330
+ div {
331
+ font-size: v-bind(size);
332
+ }
333
+ </style>` ,
334
+ {
335
+ templateOptions : {
336
+ ssr : true
337
+ }
338
+ }
339
+ )
340
+ expect ( content ) . not . toMatch ( `_useCssVars` )
341
+ } )
342
+ } )
275
343
} )
276
344
} )
Original file line number Diff line number Diff line change @@ -765,7 +765,7 @@ export function compileScript(
765
765
if (
766
766
sfc . cssVars . length &&
767
767
// no need to do this when targeting SSR
768
- ! ( options . inlineTemplate && options . templateOptions ?. ssr )
768
+ ! options . templateOptions ?. ssr
769
769
) {
770
770
ctx . helperImports . add ( CSS_VARS_HELPER )
771
771
ctx . helperImports . add ( 'unref' )
Original file line number Diff line number Diff line change @@ -55,7 +55,7 @@ export function processNormalScript(
55
55
const s = new MagicString ( content )
56
56
rewriteDefaultAST ( scriptAst . body , s , defaultVar )
57
57
content = s . toString ( )
58
- if ( cssVars . length ) {
58
+ if ( cssVars . length && ! ctx . options . templateOptions ?. ssr ) {
59
59
content += genNormalScriptCssVarsCode (
60
60
cssVars ,
61
61
bindings ,
You can’t perform that action at this time.
0 commit comments