fix(nuxt): mark entire payload as reactive (#20218)

This commit is contained in:
Daniel Roe 2023-04-12 09:42:45 +01:00 committed by GitHub
parent 67ca0815ac
commit 22f1f71e3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,5 @@
/* eslint-disable no-use-before-define */
import { getCurrentInstance, reactive, shallowReactive } from 'vue'
import { getCurrentInstance, reactive } from 'vue'
import type { App, Ref, VNode, onErrorCaptured } from 'vue'
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import type { HookCallback, Hookable } from 'hookable'
@ -181,10 +181,10 @@ export function createNuxtApp (options: CreateOptions) {
get nuxt () { return __NUXT_VERSION__ },
get vue () { return nuxtApp.vueApp.version }
},
payload: shallowReactive({
data: shallowReactive({}),
state: shallowReactive({}),
_errors: shallowReactive({}),
payload: reactive({
data: {},
state: {},
_errors: {},
...(process.client ? window.__NUXT__ ?? {} : { serverRendered: true })
}),
static: {

View File

@ -544,6 +544,7 @@ describe('errors', () => {
const { page, consoleLogs } = await renderPage('/')
await page.getByText('Increment state').click()
await page.getByText('Increment state').click()
expect(await page.innerText('div')).toContain('Some value: 3')
await page.getByText('Chunk error').click()
await page.waitForURL(url('/chunk-error'))
expect(consoleLogs.map(c => c.text).join('')).toContain('caught chunk load error')

View File

@ -5,8 +5,16 @@ import { execaCommand } from 'execa'
import { globby } from 'globby'
import { join } from 'pathe'
import { isWindows } from 'std-env'
import { isRenderingJson } from './utils'
describe.skipIf(isWindows || process.env.ECOSYSTEM_CI)('minimal nuxt application', () => {
// We only want to run this test for:
// - ubuntu
// - vite
// - in our own CI
// - using JS (default) payload rendering
// - production build
describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.env.ECOSYSTEM_CI || !isRenderingJson || process.env.TEST_ENV === 'dev')('minimal nuxt application', () => {
const rootDir = fileURLToPath(new URL('./fixtures/minimal', import.meta.url))
const publicDir = join(rootDir, '.output/public')
const serverDir = join(rootDir, '.output/server')
@ -40,7 +48,7 @@ describe.skipIf(isWindows || process.env.ECOSYSTEM_CI)('minimal nuxt application
it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"93k"')
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"92.5k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2650k"')
@ -107,5 +115,5 @@ async function analyzeSizes (pattern: string | string[], rootDir: string) {
}
function roundToKilobytes (bytes: number) {
return (Math.round(bytes / 1024) + 'k')
return (bytes / 1024).toFixed(bytes > (100 * 1024) ? 0 : 1) + 'k'
}

View File

@ -18,6 +18,7 @@
<NuxtLink to="/chunk-error" :prefetch="false">
Chunk error
</NuxtLink>
Some value: {{ someValue }}
<button @click="someValue++">
Increment state
</button>