fix(nuxt): render server components when ssr: false (#22869)

This commit is contained in:
Daniel Roe 2023-08-28 17:46:49 +01:00 committed by GitHub
parent a5cc858a4c
commit 6198a11514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -171,7 +171,7 @@ export default defineComponent({
if (import.meta.client && !nuxtApp.isHydrating && props.lazy) {
fetchComponent()
} else if (import.meta.server || !nuxtApp.isHydrating) {
} else if (import.meta.server || !nuxtApp.isHydrating || !nuxtApp.payload.serverRendered) {
await fetchComponent()
}

View File

@ -8,6 +8,7 @@ import escapeRE from 'escape-string-regexp'
import fse from 'fs-extra'
import { withoutLeadingSlash } from 'ufo'
/* eslint-disable import/no-restricted-paths */
import defu from 'defu'
import pagesModule from '../pages/module'
import metaModule from '../head/module'
import componentsModule from '../components/module'
@ -283,6 +284,12 @@ async function initNuxt (nuxt: Nuxt) {
priority: 10, // built-in that we do not expect the user to override
filePath: resolve(nuxt.options.appDir, 'components/nuxt-island')
})
if (!nuxt.options.ssr) {
nuxt.options.ssr = true
nuxt.options.nitro.routeRules ||= {}
nuxt.options.nitro.routeRules['/**'] = defu(nuxt.options.nitro.routeRules['/**'], { ssr: false })
}
}
// Add experimental cross-origin prefetch support using Speculation Rules API

View File

@ -259,7 +259,7 @@ export default defineRenderHandler(async (event): Promise<Partial<RenderResponse
noSSR:
!!(process.env.NUXT_NO_SSR) ||
event.context.nuxt?.noSSR ||
routeOptions.ssr === false ||
(routeOptions.ssr === false && !islandContext) ||
(import.meta.prerender ? PRERENDER_NO_SSR_ROUTES.has(url) : false),
head,
error: !!ssrError,