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

Commit

Permalink
perf(nuxt): tree-shake asyncData client logic from server (#7056)
Browse files Browse the repository at this point in the history
Co-authored-by: Ohb00 <43827372+OhB00@users.noreply.github.com>
  • Loading branch information
pi0 and OhB00 committed Aug 30, 2022
1 parent 5a17458 commit afc9d9b
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions packages/nuxt/src/app/composables/asyncData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,6 @@ export function useAsyncData<
// Setup nuxt instance payload
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

// Create or use a shared asyncData entity
Expand Down Expand Up @@ -181,6 +167,20 @@ export function useAsyncData<

// Client side
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) {
// 1. Hydration (server: true): no fetch
asyncData.pending.value = false
Expand Down

0 comments on commit afc9d9b

Please sign in to comment.