mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 07:32:01 +00:00
perf(nuxt): tree-shake asyncData client logic from server (#7056)
Co-authored-by: Ohb00 <43827372+OhB00@users.noreply.github.com>
This commit is contained in:
parent
5a17458af5
commit
afc9d9bfc8
@ -98,20 +98,6 @@ export function useAsyncData<
|
|||||||
// Setup nuxt instance payload
|
// Setup nuxt instance payload
|
||||||
const nuxt = useNuxtApp()
|
const nuxt = useNuxtApp()
|
||||||
|
|
||||||
// Setup hook callbacks once per instance
|
|
||||||
const instance = getCurrentInstance()
|
|
||||||
if (instance && !instance._nuxtOnBeforeMountCbs) {
|
|
||||||
instance._nuxtOnBeforeMountCbs = []
|
|
||||||
const cbs = instance._nuxtOnBeforeMountCbs
|
|
||||||
if (instance && process.client) {
|
|
||||||
onBeforeMount(() => {
|
|
||||||
cbs.forEach((cb) => { cb() })
|
|
||||||
cbs.splice(0, cbs.length)
|
|
||||||
})
|
|
||||||
onUnmounted(() => cbs.splice(0, cbs.length))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const useInitialCache = () => (nuxt.isHydrating || options.initialCache) && nuxt.payload.data[key] !== undefined
|
const useInitialCache = () => (nuxt.isHydrating || options.initialCache) && nuxt.payload.data[key] !== undefined
|
||||||
|
|
||||||
// Create or use a shared asyncData entity
|
// Create or use a shared asyncData entity
|
||||||
@ -181,6 +167,20 @@ export function useAsyncData<
|
|||||||
|
|
||||||
// Client side
|
// Client side
|
||||||
if (process.client) {
|
if (process.client) {
|
||||||
|
// Setup hook callbacks once per instance
|
||||||
|
const instance = getCurrentInstance()
|
||||||
|
if (instance && !instance._nuxtOnBeforeMountCbs) {
|
||||||
|
instance._nuxtOnBeforeMountCbs = []
|
||||||
|
const cbs = instance._nuxtOnBeforeMountCbs
|
||||||
|
if (instance) {
|
||||||
|
onBeforeMount(() => {
|
||||||
|
cbs.forEach((cb) => { cb() })
|
||||||
|
cbs.splice(0, cbs.length)
|
||||||
|
})
|
||||||
|
onUnmounted(() => cbs.splice(0, cbs.length))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (fetchOnServer && nuxt.isHydrating && key in nuxt.payload.data) {
|
if (fetchOnServer && nuxt.isHydrating && key in nuxt.payload.data) {
|
||||||
// 1. Hydration (server: true): no fetch
|
// 1. Hydration (server: true): no fetch
|
||||||
asyncData.pending.value = false
|
asyncData.pending.value = false
|
||||||
|
Loading…
Reference in New Issue
Block a user