fix(vapor): properly handle return when compiling vapor component for ssr

This commit is contained in:
Evan You 2025-03-11 19:05:46 +08:00
parent 9ff6177697
commit 3a9d6f781c
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 4 additions and 3 deletions

View File

@ -175,6 +175,7 @@ export function compileScript(
const scriptLang = script && script.lang const scriptLang = script && script.lang
const scriptSetupLang = scriptSetup && scriptSetup.lang const scriptSetupLang = scriptSetup && scriptSetup.lang
const vapor = sfc.vapor || options.vapor const vapor = sfc.vapor || options.vapor
const ssr = options.templateOptions?.ssr
if (!scriptSetup) { if (!scriptSetup) {
if (!script) { if (!script) {
@ -749,7 +750,7 @@ export function compileScript(
if ( if (
sfc.cssVars.length && sfc.cssVars.length &&
// no need to do this when targeting SSR // no need to do this when targeting SSR
!options.templateOptions?.ssr !ssr
) { ) {
ctx.helperImports.add(CSS_VARS_HELPER) ctx.helperImports.add(CSS_VARS_HELPER)
ctx.helperImports.add('unref') ctx.helperImports.add('unref')
@ -859,7 +860,7 @@ export function compileScript(
} else { } else {
// inline mode // inline mode
if (sfc.template && !sfc.template.src) { if (sfc.template && !sfc.template.src) {
if (options.templateOptions && options.templateOptions.ssr) { if (ssr) {
hasInlinedSsrRenderFn = true hasInlinedSsrRenderFn = true
} }
// inline render function mode - we are going to compile the template and // inline render function mode - we are going to compile the template and
@ -933,7 +934,7 @@ export function compileScript(
ctx.s.appendRight( ctx.s.appendRight(
endOffset, endOffset,
// vapor mode generates its own return when inlined // vapor mode generates its own return when inlined
`\n${vapor ? `` : `return `}${returned}\n}\n\n`, `\n${vapor && !ssr ? `` : `return `}${returned}\n}\n\n`,
) )
} }