From c6f769e94db7c206d801935bb0f70567e338cde6 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 25 Oct 2021 11:36:38 +0100 Subject: [PATCH] fix(nitro): inject payload for spa renderer (#1434) --- packages/nitro/src/runtime/app/render.ts | 5 ++++- packages/nuxt3/src/app/composables/asyncData.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/nitro/src/runtime/app/render.ts b/packages/nitro/src/runtime/app/render.ts index 0742e5d346..b32342284d 100644 --- a/packages/nitro/src/runtime/app/render.ts +++ b/packages/nitro/src/runtime/app/render.ts @@ -27,7 +27,10 @@ const getSSRRenderer = cachedResult(async () => { const getSPARenderer = cachedResult(async () => { const clientManifest = await getClientManifest() return (ssrContext) => { - ssrContext.nuxt = {} + ssrContext.nuxt = { + serverRendered: false, + config: publicConfig + } return { html: '
', renderResourceHints: () => '', diff --git a/packages/nuxt3/src/app/composables/asyncData.ts b/packages/nuxt3/src/app/composables/asyncData.ts index d36dbdf790..ff670dfdce 100644 --- a/packages/nuxt3/src/app/composables/asyncData.ts +++ b/packages/nuxt3/src/app/composables/asyncData.ts @@ -104,8 +104,8 @@ export function useAsyncData< return nuxt._asyncDataPromises[key] } - const fetchOnServer = options.server !== false - const clientOnly = options.server === false + const fetchOnServer = options.server !== false && nuxt.payload.serverRendered + const clientOnly = options.server === false || !nuxt.payload.serverRendered // Server side if (process.server && fetchOnServer) {