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 */ /* 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 { App, Ref, VNode, onErrorCaptured } from 'vue'
import type { RouteLocationNormalizedLoaded } from 'vue-router' import type { RouteLocationNormalizedLoaded } from 'vue-router'
import type { HookCallback, Hookable } from 'hookable' import type { HookCallback, Hookable } from 'hookable'
@ -181,10 +181,10 @@ export function createNuxtApp (options: CreateOptions) {
get nuxt () { return __NUXT_VERSION__ }, get nuxt () { return __NUXT_VERSION__ },
get vue () { return nuxtApp.vueApp.version } get vue () { return nuxtApp.vueApp.version }
}, },
payload: shallowReactive({ payload: reactive({
data: shallowReactive({}), data: {},
state: shallowReactive({}), state: {},
_errors: shallowReactive({}), _errors: {},
...(process.client ? window.__NUXT__ ?? {} : { serverRendered: true }) ...(process.client ? window.__NUXT__ ?? {} : { serverRendered: true })
}), }),
static: { static: {

View File

@ -544,6 +544,7 @@ describe('errors', () => {
const { page, consoleLogs } = await renderPage('/') const { page, consoleLogs } = await renderPage('/')
await page.getByText('Increment state').click() await page.getByText('Increment state').click()
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.getByText('Chunk error').click()
await page.waitForURL(url('/chunk-error')) await page.waitForURL(url('/chunk-error'))
expect(consoleLogs.map(c => c.text).join('')).toContain('caught chunk load 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 { globby } from 'globby'
import { join } from 'pathe' import { join } from 'pathe'
import { isWindows } from 'std-env' 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 rootDir = fileURLToPath(new URL('./fixtures/minimal', import.meta.url))
const publicDir = join(rootDir, '.output/public') const publicDir = join(rootDir, '.output/public')
const serverDir = join(rootDir, '.output/server') 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 () => { it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir) 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) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2650k"') expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2650k"')
@ -107,5 +115,5 @@ async function analyzeSizes (pattern: string | string[], rootDir: string) {
} }
function roundToKilobytes (bytes: number) { 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"> <NuxtLink to="/chunk-error" :prefetch="false">
Chunk error Chunk error
</NuxtLink> </NuxtLink>
Some value: {{ someValue }}
<button @click="someValue++"> <button @click="someValue++">
Increment state Increment state
</button> </button>