Compare commits

...

6 Commits

Author SHA1 Message Date
Julien Huang
9f44136ce8
Merge 77a96a27f4 into b0729241bc 2025-02-18 06:13:46 +01:00
Julien Huang
77a96a27f4 fix: try call instance related composables earlier 2024-08-24 18:04:05 +02:00
Julien Huang
2a47785ddd fix: wrap legacyasyncdata with runWithCOntext 2024-08-24 17:27:27 +02:00
Julien Huang
3161c1545e fix: move back into Promise.resolve 2024-08-23 00:16:33 +02:00
Julien Huang
1ac48fe0b7 fix: result 2024-08-23 00:14:54 +02:00
Julien Huang
47ac6bb843 fix(nuxt): don't wrap setup with runWithContext 2024-08-23 00:08:19 +02:00

View File

@ -1,5 +1,5 @@
import { getCurrentInstance, reactive, toRefs } from 'vue'
import type { DefineComponent, defineComponent } from 'vue'
import type { ComponentInternalInstance, DefineComponent, defineComponent } from 'vue'
import { useHead } from '@unhead/vue'
import type { NuxtApp } from '../nuxt'
import { useNuxtApp } from '../nuxt'
@ -9,10 +9,8 @@ import { createError } from './error'
export const NuxtComponentIndicator = '__nuxt_component'
async function runLegacyAsyncData (res: Record<string, any> | Promise<Record<string, any>>, fn: (nuxtApp: NuxtApp) => Promise<Record<string, any>>) {
async function runLegacyAsyncData (res: Record<string, any> | Promise<Record<string, any>>, vm: ComponentInternalInstance, route: ReturnType<typeof useRoute>, fn: (nuxtApp: NuxtApp) => Promise<Record<string, any>>) {
const nuxtApp = useNuxtApp()
const route = useRoute()
const vm = getCurrentInstance()!
const { fetchKey, _fetchKeyBase } = vm.proxy!.$options
const key = (typeof fetchKey === 'function' ? fetchKey(() => '') : fetchKey) ||
([_fetchKeyBase, route.fullPath, route.matched.findIndex(r => Object.values(r.components || {}).includes(vm.type))].join(':'))
@ -48,11 +46,12 @@ export const defineNuxtComponent: typeof defineComponent =
...options,
setup (props, ctx) {
const nuxtApp = useNuxtApp()
const res = setup ? Promise.resolve(nuxtApp.runWithContext(() => setup(props, ctx))).then(r => r || {}) : {}
const res = setup ? Promise.resolve(setup(props, ctx)).then(r => r || {}) : {}
const promises: Promise<any>[] = []
if (options.asyncData) {
promises.push(runLegacyAsyncData(res, options.asyncData))
const route = useRoute()
const vm = getCurrentInstance()!
promises.push(nuxtApp.runWithContext(() => runLegacyAsyncData(res, vm, route, options.asyncData)))
}
if (options.head) {