Skip to content

Commit

Permalink
fix(nuxt): manually assign payload reactivity when ssr: false (nuxt…
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 11, 2024
1 parent bdf8f9e commit b17aa3f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
8 changes: 5 additions & 3 deletions packages/nuxt/src/app/composables/payload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -95,19 +96,20 @@ 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
}

const el = document.getElementById('__NUXT_DATA__')
if (!el) {
return {}
return {} as Partial<NuxtPayload>
}

const inlineData = await parsePayload(el.textContent || '')
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'>
Expand Down
4 changes: 0 additions & 4 deletions packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b17aa3f

Please sign in to comment.