Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
fix(nuxt): prefer nuxt app context over getCurrentInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 14, 2022
1 parent 92c5a94 commit ee03e0d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/nuxt/src/app/nuxt.ts
Expand Up @@ -236,17 +236,17 @@ export function callWithNuxt<T extends (...args: any[]) => any> (nuxt: NuxtApp |
* Returns the current Nuxt instance.
*/
export function useNuxtApp () {
const vm = getCurrentInstance()
const nuxtAppInstance = nuxtAppCtx.use()

if (!vm) {
const nuxtAppInstance = nuxtAppCtx.use()
if (!nuxtAppInstance) {
if (!nuxtAppInstance) {
const vm = getCurrentInstance()
if (!vm) {
throw new Error('nuxt instance unavailable')
}
return nuxtAppInstance
return vm.appContext.app.$nuxt as NuxtApp
}

return vm.appContext.app.$nuxt as NuxtApp
return nuxtAppInstance
}

export function useRuntimeConfig (): RuntimeConfig {
Expand Down

0 comments on commit ee03e0d

Please sign in to comment.