mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): manually assign payload reactivity when ssr: false
(#27542)
This commit is contained in:
parent
bdf8f9e0dd
commit
b17aa3f08e
@ -3,6 +3,7 @@ import { parse } from 'devalue'
|
|||||||
import { useHead } from '@unhead/vue'
|
import { useHead } from '@unhead/vue'
|
||||||
import { getCurrentInstance, onServerPrefetch } from 'vue'
|
import { getCurrentInstance, onServerPrefetch } from 'vue'
|
||||||
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
import { useNuxtApp, useRuntimeConfig } from '../nuxt'
|
||||||
|
import type { NuxtPayload } from '../nuxt'
|
||||||
|
|
||||||
import { useRoute } from './router'
|
import { useRoute } from './router'
|
||||||
import { getAppManifest, getRouteRules } from './manifest'
|
import { getAppManifest, getRouteRules } from './manifest'
|
||||||
@ -95,11 +96,12 @@ export async function isPrerendered (url = useRoute().path) {
|
|||||||
return !!rules.prerender && !rules.redirect
|
return !!rules.prerender && !rules.redirect
|
||||||
}
|
}
|
||||||
|
|
||||||
let payloadCache: any = null
|
let payloadCache: NuxtPayload | null = null
|
||||||
|
|
||||||
/** @since 3.4.0 */
|
/** @since 3.4.0 */
|
||||||
export async function getNuxtClientPayload () {
|
export async function getNuxtClientPayload () {
|
||||||
if (import.meta.server) {
|
if (import.meta.server) {
|
||||||
return
|
return null
|
||||||
}
|
}
|
||||||
if (payloadCache) {
|
if (payloadCache) {
|
||||||
return payloadCache
|
return payloadCache
|
||||||
@ -107,7 +109,7 @@ export async function getNuxtClientPayload () {
|
|||||||
|
|
||||||
const el = document.getElementById('__NUXT_DATA__')
|
const el = document.getElementById('__NUXT_DATA__')
|
||||||
if (!el) {
|
if (!el) {
|
||||||
return {}
|
return {} as Partial<NuxtPayload>
|
||||||
}
|
}
|
||||||
|
|
||||||
const inlineData = await parsePayload(el.textContent || '')
|
const inlineData = await parsePayload(el.textContent || '')
|
||||||
|
@ -69,7 +69,7 @@ export interface NuxtSSRContext extends SSRContext {
|
|||||||
/** whether we are rendering an SSR error */
|
/** whether we are rendering an SSR error */
|
||||||
error?: boolean
|
error?: boolean
|
||||||
nuxt: _NuxtApp
|
nuxt: _NuxtApp
|
||||||
payload: NuxtPayload
|
payload: Partial<NuxtPayload>
|
||||||
head: VueHeadClient<MergeHead>
|
head: VueHeadClient<MergeHead>
|
||||||
/** This is used solely to render runtime config with SPA renderer. */
|
/** This is used solely to render runtime config with SPA renderer. */
|
||||||
config?: Pick<RuntimeConfig, 'public' | 'app'>
|
config?: Pick<RuntimeConfig, 'public' | 'app'>
|
||||||
|
@ -165,11 +165,7 @@ const getSPARenderer = lazyCachedFunction(async () => {
|
|||||||
const config = useRuntimeConfig(ssrContext.event)
|
const config = useRuntimeConfig(ssrContext.event)
|
||||||
ssrContext.modules = ssrContext.modules || new Set<string>()
|
ssrContext.modules = ssrContext.modules || new Set<string>()
|
||||||
ssrContext!.payload = {
|
ssrContext!.payload = {
|
||||||
_errors: {},
|
|
||||||
serverRendered: false,
|
serverRendered: false,
|
||||||
data: {},
|
|
||||||
state: {},
|
|
||||||
once: new Set<string>(),
|
|
||||||
}
|
}
|
||||||
ssrContext.config = {
|
ssrContext.config = {
|
||||||
public: config.public,
|
public: config.public,
|
||||||
|
Loading…
Reference in New Issue
Block a user