fix(nuxt): keep state in the initial state instead of extracting it (#7567)

This commit is contained in:
pooya parsa 2022-09-16 12:49:00 +02:00 committed by GitHub
parent c1ed6ecc3c
commit 1ebdef77a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 4 deletions

View File

@ -16,6 +16,5 @@ export default defineNuxtPlugin((nuxtApp) => {
const payload = await loadPayload(to.path)
if (!payload) { return }
Object.assign(nuxtApp.payload.data, payload.data)
Object.assign(nuxtApp.payload.state, payload.state)
})
})

View File

@ -297,9 +297,9 @@ function renderPayloadResponse (ssrContext: NuxtSSRContext) {
}
function splitPayload (ssrContext: NuxtSSRContext) {
const { data, state, prerenderedAt, ...initial } = ssrContext.payload
const { data, prerenderedAt, ...initial } = ssrContext.payload
return {
initial: { ...initial, prerenderedAt },
payload: { data, state, prerenderedAt }
payload: { data, prerenderedAt }
}
}

View File

@ -590,7 +590,7 @@ describe.skipIf(process.env.NUXT_TEST_DEV || isWindows)('payload rendering', ()
it('renders a payload', async () => {
const payload = await $fetch('/random/a/_payload.js', { responseType: 'text' })
expect(payload).toMatch(
/export default \{data:\{\$frand_a:\[[^\]]*\]\},state:\{"\$srandom:rand_a":\d*,"\$srandom:default":\d*\},prerenderedAt:\d*\}/
/export default \{data:\{\$frand_a:\[[^\]]*\]\},prerenderedAt:\d*\}/
)
})