mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): unset context after app is created (#19753)
This commit is contained in:
parent
5a1cfa8b66
commit
4ca2dccd38
@ -34,7 +34,7 @@ if (process.server) {
|
||||
await applyPlugins(nuxt, plugins)
|
||||
await nuxt.hooks.callHook('app:created', vueApp)
|
||||
} catch (err) {
|
||||
await nuxt.callHook('app:error', err)
|
||||
await nuxt.hooks.callHook('app:error', err)
|
||||
nuxt.payload.error = (nuxt.payload.error || err) as any
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
import { getCurrentInstance, reactive } from 'vue'
|
||||
import type { App, onErrorCaptured, VNode, Ref } from 'vue'
|
||||
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||
import type { Hookable } from 'hookable'
|
||||
import type { Hookable, HookCallback } from 'hookable'
|
||||
import { createHooks } from 'hookable'
|
||||
import { getContext } from 'unctx'
|
||||
import type { SSRContext } from 'vue-bundle-renderer/runtime'
|
||||
@ -187,6 +187,18 @@ export function createNuxtApp (options: CreateOptions) {
|
||||
|
||||
nuxtApp.hooks = createHooks<RuntimeNuxtHooks>()
|
||||
nuxtApp.hook = nuxtApp.hooks.hook
|
||||
|
||||
if (process.server) {
|
||||
async function contextCaller (hooks: HookCallback[], args: any[]) {
|
||||
for (const hook of hooks) {
|
||||
await nuxtAppCtx.call(nuxtApp, () => hook(...args))
|
||||
}
|
||||
}
|
||||
// Patch callHook to preserve NuxtApp context on server
|
||||
// TODO: Refactor after https://github.com/unjs/hookable/issues/74
|
||||
nuxtApp.hooks.callHook = (name: any, ...args: any[]) => nuxtApp.hooks.callHookWith(contextCaller, name, ...args)
|
||||
}
|
||||
|
||||
nuxtApp.callHook = nuxtApp.hooks.callHook
|
||||
|
||||
nuxtApp.provide = (name: string, value: any) => {
|
||||
|
@ -40,7 +40,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {
|
||||
|
||||
it('default server bundle size', async () => {
|
||||
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
|
||||
expect(stats.server.totalBytes).toBeLessThan(93600)
|
||||
expect(stats.server.totalBytes).toBeLessThan(93800)
|
||||
|
||||
const modules = await analyzeSizes('node_modules/**/*', serverDir)
|
||||
expect(modules.totalBytes).toBeLessThan(2693900)
|
||||
|
Loading…
Reference in New Issue
Block a user