MCPcopy
hub / github.com/nuxt/nuxt / createInitialFetch

Function createInitialFetch

packages/nuxt/src/app/composables/asyncData.ts:366–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

364
365 // Create or use a shared asyncData entity
366 function createInitialFetch () {
367 const initialFetchOptions: AsyncDataExecuteOptions = { cause: 'initial', dedupe: opts.dedupe }
368 const existing = nuxtApp._asyncData[key.value]
369 if (!existing?._init) {
370 initialFetchOptions.cachedData = opts.getCachedData!(key.value, nuxtApp, { cause: 'initial' })
371 nuxtApp._asyncData[key.value] = buildAsyncData(nuxtApp, key.value, _handler, opts, initialFetchOptions.cachedData)
372 nuxtApp._asyncData[key.value]!._initialCachedData = initialFetchOptions.cachedData
373 } else if (nuxtApp._asyncDataPromises[key.value]) {
374 // reuse the cache lookup performed by the first concurrent caller while their fetch is still in flight
375 initialFetchOptions.cachedData = existing._initialCachedData
376 }
377 // otherwise let execute() perform a fresh getCachedData lookup so subscribers that mount
378 // after the initial fetch has settled still go through getCachedData (#35116)
379 return () => nuxtApp._asyncData[key.value]!.execute(initialFetchOptions)
380 }
381
382 const initialFetch = createInitialFetch()
383 const asyncData = nuxtApp._asyncData[key.value]!

Callers 1

useAsyncDataFunction · 0.85

Calls 1

buildAsyncDataFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…