fix(nuxt): manually assign payload reactivity when `ssr: false` (#27542)

This commit is contained in:
Daniel Roe 2024-06-11 19:59:48 +01:00 committed by GitHub
parent bdf8f9e0dd
commit b17aa3f08e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 8 deletions

View File

@ -3,6 +3,7 @@ import { parse } from 'devalue'
import { useHead } from '@unhead/vue'
import { getCurrentInstance, onServerPrefetch } from 'vue'
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
import type { NuxtPayload } from '../nuxt'
import { useRoute } from './router'
import { getAppManifest, getRouteRules } from './manifest'
@ -95,11 +96,12 @@ export async function isPrerendered (url = useRoute().path) {
return !!rules.prerender && !rules.redirect
}
let payloadCache: any = null
let payloadCache: NuxtPayload | null = null
/** @since 3.4.0 */
export async function getNuxtClientPayload () {
if (import.meta.server) {
return
return null
}
if (payloadCache) {
return payloadCache
@ -107,7 +109,7 @@ export async function getNuxtClientPayload () {
const el = document.getElementById('__NUXT_DATA__')
if (!el) {
return {}
return {} as Partial<NuxtPayload>
}
const inlineData = await parsePayload(el.textContent || '')

View File

@ -69,7 +69,7 @@ export interface NuxtSSRContext extends SSRContext {
/** whether we are rendering an SSR error */
error?: boolean
nuxt: _NuxtApp
payload: NuxtPayload
payload: Partial<NuxtPayload>
head: VueHeadClient<MergeHead>
/** This is used solely to render runtime config with SPA renderer. */
config?: Pick<RuntimeConfig, 'public' | 'app'>

View File

@ -165,11 +165,7 @@ const getSPARenderer = lazyCachedFunction(async () => {
const config = useRuntimeConfig(ssrContext.event)
ssrContext.modules = ssrContext.modules || new Set<string>()
ssrContext!.payload = {
_errors: {},
serverRendered: false,
data: {},
state: {},
once: new Set<string>(),
}
ssrContext.config = {
public: config.public,