mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +00:00
fix(nuxt): mark entire payload as reactive (#20218)
This commit is contained in:
parent
67ca0815ac
commit
22f1f71e3e
@ -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: {
|
||||||
|
@ -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')
|
||||||
|
@ -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'
|
||||||
}
|
}
|
||||||
|
1
test/fixtures/basic/pages/index.vue
vendored
1
test/fixtures/basic/pages/index.vue
vendored
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user