fix(nuxt): check if _scope is active before calling run function (#26756) (#26904)

This commit is contained in:
Nicolas Payot 2024-04-23 11:34:41 +02:00 committed by GitHub
parent 7562ecabfb
commit 1a91b120ee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -254,7 +254,12 @@ export function createNuxtApp (options: CreateOptions) {
static: { static: {
data: {}, data: {},
}, },
runWithContext: (fn: any) => nuxtApp._scope.run(() => callWithNuxt(nuxtApp, fn)), runWithContext (fn: any) {
if (nuxtApp._scope.active) {
return nuxtApp._scope.run(() => callWithNuxt(nuxtApp, fn))
}
return callWithNuxt(nuxtApp, fn)
},
isHydrating: import.meta.client, isHydrating: import.meta.client,
deferHydration () { deferHydration () {
if (!nuxtApp.isHydrating) { return () => {} } if (!nuxtApp.isHydrating) { return () => {} }